Guest User

Untitled

a guest
Dec 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class Button extends React. Component {
  2. handleClick = () => {
  3. this.props.onClickFunction(this.props.incrementValue);
  4. };
  5.  
  6. render() {
  7. return(
  8. <button
  9. onClick={this.handleClick}> + {this.props.incrementValue}</button>
  10. );
  11. }
  12. }
  13.  
  14. const Result = (props) => {
  15. return (
  16. <div> {props.counter}</div>
  17. );
  18. };
  19.  
  20. class App extends React.Component {
  21. state = {counter: 0};
  22.  
  23. incrementCounter = (incrementValue) => {
  24. this.setState((prevState) => ({
  25. counter: prevState.counter + incrementValue
  26. }));
  27. };
  28.  
  29. render() {
  30. return (
  31. <div>
  32. <Button incrementValue={1} onClickFunction={this.incrementCounter} />
  33. <Button incrementValue={5} onClickFunction={this.incrementCounter} />
  34. <Button incrementValue={10} onClickFunction={this.incrementCounter} />
  35. <Button incrementValue={100} onClickFunction={this.incrementCounter} />
  36. <Result counter={this.state.counter}/>
  37. </div>
  38. );
  39. }
  40. }
  41.  
  42. ReactDOM.render(<App />, mountNode);
Add Comment
Please, Sign In to add comment