Advertisement
irobust

React demo 01

Jul 10th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const MyButton = (props) => {
  2.     var handleOnClick = () => {};
  3.     return(
  4.     <button onClick={handleOnClick}>Counter {props.start}</button>
  5.     // React.createElement("button", null, "Go")
  6.   );
  7. }
  8.  
  9. class Button extends React.Component{
  10.     constructor(props){
  11.     super(props);
  12.     this.state = {counter: this.props.start};
  13.   }
  14.  
  15.   handleOnClick = () => {
  16.     this.setState((prevState) => {
  17.         return {
  18.             counter: prevState.counter + 1
  19.     }});
  20.   }
  21.  
  22.     render(){
  23.     return (
  24.         <div>
  25.         <button onClick={this.handleOnClick}>
  26.           Counter {this.props.start}</button>
  27.         <div>{this.state.counter}</div>
  28.       </div>
  29.     );
  30.   }
  31. }
  32.  
  33. ReactDOM.render(<Button start={7} />, mountNode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement