Skip to content

Instantly share code, notes, and snippets.

@adekbadek
Created November 25, 2016 16:23
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 adekbadek/38786d6933dd67cb43f5f6fff8dd8fd2 to your computer and use it in GitHub Desktop.
Save adekbadek/38786d6933dd67cb43f5f6fff8dd8fd2 to your computer and use it in GitHub Desktop.
// first, import whatever external modules will be needed
import React from 'react'
import { render } from 'react-dom'
// new 'class' App is based on the default React Component
class App extends React.Component {
// inside, there are 'methods':
// a special constructor method, called when the component is created
constructor () {
// a 'super call' has to be made before using 'this' in a component
super()
// 'this' is simply the component (less simply, it's the current context, which here happens to be the component)
// a 'state' in React is everything that can change. Try to have as little state as possible
this.state = {
who: "React"
}
}
// another method - 'render' - it tells React how to... render the component
render () {
return (
// this 'HTML in JS' is called JSX
<div>
{`Hello ${this.state.who}`}
</div>
)
}
}
// Finally, we use React-DOM. React can be used in many contexts, websites are just one of them.
render(<App />, document.getElementById('root'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment