Last active
March 16, 2023 23:00
-
-
Save D-Maher/8d8dc3c1b36e250c1a8b81f93bdadeee to your computer and use it in GitHub Desktop.
React component with local state
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, { useState } from "react"; | |
function Counter() { | |
const [count, setCount] = useState(0); | |
const increment = () => { | |
setCount(count + 1); | |
}; | |
const decrement = () => { | |
setCount(count - 1); | |
}; | |
return ( | |
<div> | |
<p>Count: {count}</p> | |
<button onClick={increment}>Increment</button> | |
<button onClick={decrement}>Decrement</button> | |
</div> | |
); | |
} | |
export default Counter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment