Skip to content

Instantly share code, notes, and snippets.

@such
Last active November 21, 2020 11:24
Show Gist options
  • Save such/eaa1c7ba595ccdbd5e3397b64a76ffff to your computer and use it in GitHub Desktop.
Save such/eaa1c7ba595ccdbd5e3397b64a76ffff to your computer and use it in GitHub Desktop.
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