bsky-app/src/state/shell/drawer-open.tsx

26 lines
670 B
TypeScript

import React from 'react'
type StateContext = boolean
type SetContext = (v: boolean) => void
const stateContext = React.createContext<StateContext>(false)
const setContext = React.createContext<SetContext>((_: boolean) => {})
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(false)
return (
<stateContext.Provider value={state}>
<setContext.Provider value={setState}>{children}</setContext.Provider>
</stateContext.Provider>
)
}
export function useIsDrawerOpen() {
return React.useContext(stateContext)
}
export function useSetDrawerOpen() {
return React.useContext(setContext)
}