Created
March 21, 2021 21:41
-
-
Save florianmartens/aaae9be31e5be3ad94575839a559683a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { useEffect, useReducer } from "react"; | |
const reducer = (state, action) => { | |
switch(action.type) { | |
case "Increment": | |
return state + 1; | |
default: | |
return state; | |
} | |
} | |
export default function App() { | |
const [state, dispatch] = useReducer(reducer, 0); | |
useEffect(() => { | |
setInterval(() => { | |
dispatch({type: "Increment"}); | |
}, 1000); | |
}, []); | |
return ( | |
<div className="App"> | |
<h1>The current count is:</h1> | |
<h2>{state}</h2> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment