import React from 'react' import * as persisted from '#/state/persisted' type StateContext = boolean | undefined type SetContext = (v: boolean) => void const stateContext = React.createContext(false) stateContext.displayName = 'UsedStarterPacksStateContext' const setContext = React.createContext((_: boolean) => {}) setContext.displayName = 'UsedStarterPacksSetContext' export function Provider({children}: {children: React.ReactNode}) { const [state, setState] = React.useState(() => persisted.get('hasCheckedForStarterPack'), ) const setStateWrapped = (v: boolean) => { setState(v) persisted.write('hasCheckedForStarterPack', v) } React.useEffect(() => { return persisted.onUpdate( 'hasCheckedForStarterPack', nextHasCheckedForStarterPack => { setState(nextHasCheckedForStarterPack) }, ) }, []) return ( {children} ) } export const useHasCheckedForStarterPack = () => React.useContext(stateContext) export const useSetHasCheckedForStarterPack = () => React.useContext(setContext)