Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active March 28, 2017 07:20
Show Gist options
  • Save StevenJL/d9d5132b336857835b68 to your computer and use it in GitHub Desktop.
Save StevenJL/d9d5132b336857835b68 to your computer and use it in GitHub Desktop.
// The simplest component is a Javascript function that takes `props`
// as an argument and returns a React element. This is called a
// "functional component" since, well, it's just a function!
function CommentBox(props) {
return <div>Hello, here is a comment: {props.content} </div>;
}
// If you're using ES 6, React components can be created
// by extending React.Component.
class CommentBox extends React.Component {
render() {
return (
// Note this <div> is not a DOM node, but an instance of a React div element
<div className="commentBox">
Hello, here is a comment: {props.content}
</div>
)
}
}
// You can render components
ReactDom.render(
<CommentBox content="My opinion matters!"/>,
document.getElementId("root")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment