Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const MyButton = (props) => {
- var handleOnClick = () => {};
- return(
- <button onClick={handleOnClick}>Counter {props.start}</button>
- // React.createElement("button", null, "Go")
- );
- }
- class Button extends React.Component{
- constructor(props){
- super(props);
- this.state = {counter: this.props.start};
- }
- handleOnClick = () => {
- this.setState((prevState) => {
- return {
- counter: prevState.counter + 1
- }});
- }
- render(){
- return (
- <div>
- <button onClick={this.handleOnClick}>
- Counter {this.props.start}</button>
- <div>{this.state.counter}</div>
- </div>
- );
- }
- }
- ReactDOM.render(<Button start={7} />, mountNode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement