Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

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

Greg Richardsonc28a61aa5e16
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<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)