Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save caviles/30fbdcab23bb6a76755b2fee806073a7 to your computer and use it in GitHub Desktop.
Save caviles/30fbdcab23bb6a76755b2fee806073a7 to your computer and use it in GitHub Desktop.
class Button extends React.Component {
handleClick = () => {
this.props.onClickFn(this.props.incrementValue);
};
render () {
return(
<button onClick={this.handleClick}>
+{this.props.incrementValue}</button>
);
}
};
//this class will be used 4to print the result to the screen
class Result extends React.Component {
render () {
return(
<div> er
{this.props.counter}
</div>
);
}
};
class App extends React.Component {
state = {counter:0};
//this will be used to incrment it will be passed to the btn class
incrementCounter = (incrementValue) => {
this.setState((prevState) => ({
counter: prevState.counter + incrementValue
}));
};
render () {
return(
<div>
<Button incrementValue={1} onClickFn={this.incrementCounter}/>
<Button incrementValue={5} onClickFn={this.incrementCounter}/>
<Button incrementValue={10} onClickFn={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