diff --git a/src/context.ts b/src/context.ts index 97e24de..2b4e89f 100644 --- a/src/context.ts +++ b/src/context.ts @@ -59,4 +59,10 @@ export const DrawerContext = React.createContext({ direction: 'bottom', }); -export const useDrawerContext = () => React.useContext(DrawerContext); +export const useDrawerContext = () => { + const context = React.useContext(DrawerContext); + if (!context) { + throw new Error('useDrawerContext must be used within a Drawer.Root'); + } + return context; +};