mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
chore(cmdk): throw error if useCommandMenu used outside of provider
This commit is contained in:
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)
|
||||
|
||||
Reference in new issue
Block a user