Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
Last active April 4, 2021 17:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Class Based Counter Example
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
state = {
counter: 0
};
handleOnClick = () => {
this.setState(prevState => ({
counter: prevState.counter + 1
}));
};
render() {
return (
<div>
<p>Counter value is: {this.state.counter} </p>
<button onClick={this.handleOnClick}>Increment</button>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment