2276cb0e75
* fix share button * Revert "fix share button" This reverts commit 3521c241729dc9bbe3dd7b62fc6e3e61e011cdf9. * tweak * Clean up context --------- Co-authored-by: Eric Bailey <git@esb.lol>
33 lines
697 B
TypeScript
33 lines
697 B
TypeScript
import React from 'react'
|
|
|
|
import type {ContextType, ItemContextType} from '#/components/Menu/types'
|
|
|
|
export const Context = React.createContext<ContextType>({
|
|
// @ts-ignore
|
|
control: null,
|
|
})
|
|
|
|
export const ItemContext = React.createContext<ItemContextType>({
|
|
disabled: false,
|
|
})
|
|
|
|
export function useMenuContext() {
|
|
const context = React.useContext(Context)
|
|
|
|
if (!context) {
|
|
throw new Error('useMenuContext must be used within a Context.Provider')
|
|
}
|
|
|
|
return context
|
|
}
|
|
|
|
export function useMenuItemContext() {
|
|
const context = React.useContext(ItemContext)
|
|
|
|
if (!context) {
|
|
throw new Error('useMenuItemContext must be used within a Context.Provider')
|
|
}
|
|
|
|
return context
|
|
}
|