Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at post-text-option 42 lines 1.3 kB view raw
1import React from 'react' 2 3import * as persisted from '#/state/persisted' 4 5type StateContext = boolean | undefined 6type SetContext = (v: boolean) => void 7 8const stateContext = React.createContext<StateContext>(false) 9stateContext.displayName = 'UsedStarterPacksStateContext' 10const setContext = React.createContext<SetContext>((_: boolean) => {}) 11setContext.displayName = 'UsedStarterPacksSetContext' 12 13export function Provider({children}: {children: React.ReactNode}) { 14 const [state, setState] = React.useState<StateContext>(() => 15 persisted.get('hasCheckedForStarterPack'), 16 ) 17 18 const setStateWrapped = (v: boolean) => { 19 setState(v) 20 persisted.write('hasCheckedForStarterPack', v) 21 } 22 23 React.useEffect(() => { 24 return persisted.onUpdate( 25 'hasCheckedForStarterPack', 26 nextHasCheckedForStarterPack => { 27 setState(nextHasCheckedForStarterPack) 28 }, 29 ) 30 }, []) 31 32 return ( 33 <stateContext.Provider value={state}> 34 <setContext.Provider value={setStateWrapped}> 35 {children} 36 </setContext.Provider> 37 </stateContext.Provider> 38 ) 39} 40 41export const useHasCheckedForStarterPack = () => React.useContext(stateContext) 42export const useSetHasCheckedForStarterPack = () => React.useContext(setContext)