Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save florianmartens/aaae9be31e5be3ad94575839a559683a to your computer and use it in GitHub Desktop.
Save florianmartens/aaae9be31e5be3ad94575839a559683a to your computer and use it in GitHub Desktop.
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