Skip to content

Instantly share code, notes, and snippets.

@Salman18
Created October 25, 2017 06:41
Show Gist options
  • Save Salman18/b8dbde23c5394f97017351705bea543d to your computer and use it in GitHub Desktop.
Save Salman18/b8dbde23c5394f97017351705bea543d to your computer and use it in GitHub Desktop.
Using Class and Functional Based Component
class Button extends React.Component {
render() {
return (
<button onClick={this.props.onClickFunction}>
{this.props.incrementValue}
</button>
);
}
}
const Result = (props) => {
return (
<div>{props.counter}</div>
);
}
class App extends React.Component {
state = { counter: 0};
incrementCounter = () => {
this.setState( (prevState) => ({
counter: prevState.counter+1
}));
};
render () {
return (
<div>
<Button incrementValue={"+1"} 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