Skip to content

Instantly share code, notes, and snippets.

@nickkaczmarek
Last active June 22, 2019 01:45
Show Gist options
  • Save nickkaczmarek/c15193f9251a921be7511a6105cf8ac7 to your computer and use it in GitHub Desktop.
Save nickkaczmarek/c15193f9251a921be7511a6105cf8ac7 to your computer and use it in GitHub Desktop.
dotnet core react component useState
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