Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
Last active April 4, 2021 17:00
Show Gist options
  • Save myogeshchavan97/38c0ad6b022082a8ba1fcbcd6ef3f24c to your computer and use it in GitHub Desktop.
Save myogeshchavan97/38c0ad6b022082a8ba1fcbcd6ef3f24c to your computer and use it in GitHub Desktop.
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