diff --git a/packages/ui/src/components/Command/CommandMenuProvider.tsx b/packages/ui/src/components/Command/CommandMenuProvider.tsx index 7a5f46d2cbf..7ffc283ca9f 100644 --- a/packages/ui/src/components/Command/CommandMenuProvider.tsx +++ b/packages/ui/src/components/Command/CommandMenuProvider.tsx @@ -9,7 +9,15 @@ export interface CommandMenuContextValue { setIsLoading: React.Dispatch> } export const CommandMenuContext = createContext(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)