Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
Last active November 16, 2020 02:56
  • 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?
Counter Example with class properties syntax
import React from "react";
import ReactDOM from "react-dom";
class Counter extends React.Component {
state = {
counter: 0
};
handleAddOne = () => {
this.setState(prevState => {
return {
counter: prevState.counter + 1
};
});
};
render() {
return (
<div>
<div>Counter: {this.state.counter}</div>
<button onClick={this.handleAddOne}>Add One</button>
</div>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<Counter />, rootElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment