chore(cmdk): throw error if useCommandMenu used outside of provider

This commit is contained in:
Greg Richardson committed 2023-03-23 13:19:10 -06:00
1 parent 3ca438a647
commit c28a61aa5e
1 file changed
+9 -1
@@ -9,7 +9,15 @@ export interface CommandMenuContextValue {
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>
}
export const CommandMenuContext = createContext<CommandMenuContextValue>(undefined)
export const useCommandMenu = () => useContext(CommandMenuContext)
export const useCommandMenu = () => {
const context = useContext(CommandMenuContext)
if (context === undefined) {
throw new Error('useCommandMenu was used outside of CommandMenuProvider')
}
return context
}
const CommandMenuProvider = ({ children }: PropsWithChildren<{}>) => {
const [isOpen, setIsOpen] = useState(false)