Created
November 6, 2016 23:59
-
-
Save Shruubi/3e02746e2057e255aa528ea132cc87b2 to your computer and use it in GitHub Desktop.
Example es6 react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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