Created
January 2, 2019 13:10
You might not need a build toolchain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: props.count || 0 | |
}; | |
this.updateCount = this.updateCount.bind(this); | |
} | |
updateCount(increment) { | |
const { count } = this.state; | |
if (increment) { | |
this.setState({ | |
count: count + 1 | |
}); | |
} else { | |
this.setState({ | |
count: count - 1 | |
}); | |
} | |
} | |
render() { | |
const { count } = this.state; | |
return React.createElement( | |
"div", | |
null, | |
React.createElement("p", null, "The current count is ", count), | |
React.createElement( | |
"button", | |
{ | |
type: "button", | |
onClick: () => { | |
return this.updateCount(true); | |
} | |
}, | |
"Increment" | |
), | |
React.createElement( | |
"button", | |
{ | |
type: "button", | |
onClick: () => { | |
return this.updateCount(false); | |
} | |
}, | |
"Decrement" | |
) | |
); | |
} | |
} | |
export default Counter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment