drawerContainerRefContext.tsx 476 B

123456789101112131415
  1. import {createContext, type RefObject, useContext} from 'react';
  2. type DrawerContainerRef = RefObject<HTMLDivElement> | null;
  3. export const DrawerContainerRefContext = createContext<DrawerContainerRef>(null);
  4. export const useDrawerContainerRef = () => {
  5. const context = useContext(DrawerContainerRefContext);
  6. if (context === null) {
  7. throw new Error(
  8. 'useDrawerContainerRef must be used within DrawerContainerRefContext.Provider'
  9. );
  10. }
  11. return context;
  12. };