Skip to content

Instantly share code, notes, and snippets.

@Shruubi
Created November 6, 2016 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shruubi/3e02746e2057e255aa528ea132cc87b2 to your computer and use it in GitHub Desktop.
Save Shruubi/3e02746e2057e255aa528ea132cc87b2 to your computer and use it in GitHub Desktop.
Example es6 react
//import the react library
import * as React from "react";
//ExampleWidget inherits functionality of React.Component
//we also need to export default to make this widget available
//to the rest of our app
export default class ExampleWidget extends React.Component {
//constructor is called when the widget is created
constructor(props) {
//props are the things passed to a html element, e.g. id is a prop on <div id="test"></div>
super(props);
}
//this is the method that outputs our HTML
render() {
//Notice how we mix HTML and Javascript? This is called JSX syntax
return (
<div>
<h1 className="greeting">Hello {{ this.props.name }}</h1>
</div>
);
}
}
//we can use this widget by saying <ExampleWidget name="Damon" /> which will render out
// <div><h1 class="greeting">Hello Damon</h1></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment