Skip to content

Instantly share code, notes, and snippets.

@Blazing-Mike
Created June 17, 2022 19:48
Show Gist options
  • Save Blazing-Mike/a43165e06977de86fb51564545e065ad to your computer and use it in GitHub Desktop.
Save Blazing-Mike/a43165e06977de86fb51564545e065ad to your computer and use it in GitHub Desktop.
a simple counter in react
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
function Counter() {
const [count, setCount] = useState(0);
function increment(){
setCount(count + 1)
}
return (
<div id="mainArea">
<p>button count: <span>{count}</span></p>
<button id="mainButton" onClick={increment}>Increase</button>
</div>
);
}
ReactDOM.render(
<Counter />,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment