Created
January 19, 2021 16:39
-
-
Save jogilvyt/cf14e97a94fd8acb99db40ac0948af84 to your computer and use it in GitHub Desktop.
React counter with localStorage hook
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 useStateWithLocalStorage from "../hooks/useStateWithLocalStorage"; | |
function App() { | |
const [count, setCount] = useStateWithLocalStorage(0, "count"); | |
return ( | |
<div> | |
<h1>Counter</h1> | |
<p>Number: {count}</p> | |
<button onClick={() => setCount(count - 1)}>-1</button> | |
<button onClick={() => setCount(count + 1)}>+1</button> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment