Last active
June 22, 2019 01:45
-
-
Save nickkaczmarek/c15193f9251a921be7511a6105cf8ac7 to your computer and use it in GitHub Desktop.
dotnet core react component useState
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
import React from 'react'; | |
export function Counter() { | |
const [currentCount, incrementCounter] = React.useState(0); | |
return ( | |
<div> | |
<h1>Counter</h1> | |
<p>This is a simple example of a React component.</p> | |
<p>Current count: <strong>{currentCount}</strong></p> | |
<button className="btn btn-primary" onClick={() => incrementCounter(currentCount + 1)}>Increment</button> | |
</div> | |
); | |
} | |
// export class Counter extends Component { | |
// // static displayName = Counter.name; | |
// constructor(props) { | |
// super(props); | |
// this.state = { currentCount: 0 }; | |
// this.incrementCounter = this.incrementCounter.bind(this); | |
// } | |
// incrementCounter() { | |
// this.setState({ | |
// currentCount: this.state.currentCount + 1 | |
// }); | |
// } | |
// render() { | |
// return ( | |
// <div> | |
// <h1>Counter</h1> | |
// <p>This is a simple example of a React component.</p> | |
// <p>Current count: <strong>{this.state.currentCount}</strong></p> | |
// <button className="btn btn-primary" onClick={this.incrementCounter}>Increment</button> | |
// </div> | |
// ); | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment