Skip to content

Instantly share code, notes, and snippets.

@okjodom
Created May 14, 2018 09:34
Show Gist options
  • Save okjodom/1ef06ec5c9c3c17259cbaee6b786495c to your computer and use it in GitHub Desktop.
Save okjodom/1ef06ec5c9c3c17259cbaee6b786495c to your computer and use it in GitHub Desktop.
React JS book prop using ES6 classes
import React from 'react'; // super class
class Book extends React.Component{ // sub class extends super class
constructor (){ // all classes have a constructor method
super(props); // must do this to link sub class to super class properties
this.id = "#B00K123";
this.title = "We All Don't Know JS";
this.description = "The book everyone needs to read";
this.price = 0;
}
render (){ // a render method for the class.
return (
return (
<div key={book.id}>
<h2>{book.title}</h2>
<p>{book.description}</p>
<p><strong>{book.price}</strong></p>
</div>
)
);
}
yadaYada (){ // all class methods are declared in the class: compact yada
return 'Yada Yada!';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment