Skip to content

Instantly share code, notes, and snippets.

@saurabhpati
Created July 12, 2018 16:57
Show Gist options
  • Save saurabhpati/58211a205832612e2bf0f459b8b03f11 to your computer and use it in GitHub Desktop.
Save saurabhpati/58211a205832612e2bf0f459b8b03f11 to your computer and use it in GitHub Desktop.
component hierarchy
class Button extends React.Component {
render () {
return (
<button onClick={this.props.onClickFunction}>+1</button>
)
}
}
const Result = (props) => {
return (
<div>{props.counter}</div>
);
}
class App extends React.Component {
constructor() {
super()
this.state = {counter: 0};
}
incrementCounter = () => {
this.setState(prevState => ({ counter: ++prevState.counter }));
}
render() {
return (
<div>
<Button onClickFunction={this.incrementCounter}/>
<Result counter={this.state.counter}/>
</div>
)
}
}
ReactDOM.render(<App />, mountNode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment