Created
September 9, 2018 09:10
-
-
Save umair-syed-webjet/d476f7209cf978b3603d4689a4e905c5 to your computer and use it in GitHub Desktop.
basic react component
This file contains hidden or 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 Button extends React.Component { | |
state = { counter: 0}; | |
handleClick = () => { | |
this.setState({ | |
counter:this.state.counter + 1 | |
}) | |
}; | |
render() { | |
return ( | |
<button onClick={this.handleClick}> | |
{this.state.counter} | |
</button> | |
); | |
} | |
} | |
ReactDOM.render(<Button />, mountNode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//setState is async so this is better
handleClick = () => {
this.setState((prevState) => {
return {counter: prevState.counter + 1 };
})
};