import { useReducer } from 'react'; import { useLocalStorage } from '../util/PersistentStorage'; import { nextState } from '../util/StateHelper'; const Persistent = (() => { const [getEnabled, setEnabled] = useLocalStorage('polling.enabled', true); return { getEnabled, setEnabled } })(); // <<--- Execute export const pollingInitialState = { enabled: Persistent.getEnabled() === 'true', games: false, leaderboard: false }; export function pollingReducer(curntState, action) { switch (action.type) { case 'toggleOnOff': return { ...curntState, enabled: Persistent.setEnabled(!curntState.enabled) }; case 'next': return nextState(curntState, action); default: throw Error('Unknown action.type:' + action.type); } } export default function usePollingReducer() { return useReducer(pollingReducer, pollingInitialState); }