Created
July 12, 2018 16:57
-
-
Save saurabhpati/58211a205832612e2bf0f459b8b03f11 to your computer and use it in GitHub Desktop.
component hierarchy
This file contains hidden or 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
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