Skip to content

Commit

Permalink
add warning when drawer context is used outside of scope (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
rortan134 committed May 7, 2024
1 parent e2cfd4d commit 0364980
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ export const DrawerContext = React.createContext<DrawerContextValue>({
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;
};

0 comments on commit 0364980

Please sign in to comment.