Last active
November 21, 2020 11:24
-
-
Save such/eaa1c7ba595ccdbd5e3397b64a76ffff to your computer and use it in GitHub Desktop.
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
export const TickerContext = React.createContext(null); | |
export function TickerProvider({ children }) { | |
const [now, setNow] = useState(new Date()); | |
useEffect(() => { | |
const interval = setInterval(() => setNow(new Date()), 1000); | |
return () => clearInterval(interval); | |
}, []); | |
return ( | |
<TickerContext.Provider value={{now}}> | |
{children} | |
</TickerContext.Provider> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment