blob: e1000b90b65073b82d08e7c3c1ec5c385386b40a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import React from 'react'
type StateContext = boolean
type ApiContext = (hasNew: boolean) => void
const stateContext = React.createContext<StateContext>(false)
stateContext.displayName = 'HomeBadgeStateContext'
const apiContext = React.createContext<ApiContext>((_: boolean) => {})
apiContext.displayName = 'HomeBadgeApiContext'
export function Provider({children}: React.PropsWithChildren<{}>) {
const [state, setState] = React.useState(false)
return (
<stateContext.Provider value={state}>
<apiContext.Provider value={setState}>{children}</apiContext.Provider>
</stateContext.Provider>
)
}
export function useHomeBadge() {
return React.useContext(stateContext)
}
export function useSetHomeBadge() {
return React.useContext(apiContext)
}
|