CommandPaletteContext.tsx raw

   1  import React from "react";
   2  import { useCommandPalette } from "src/hooks/useCommandPalette";
   3  
   4  interface CommandPaletteContextType {
   5    open: boolean;
   6    setOpen: (open: boolean) => void;
   7  }
   8  
   9  const CommandPaletteContext =
  10    React.createContext<CommandPaletteContextType | null>(null);
  11  
  12  export function CommandPaletteProvider({
  13    children,
  14  }: {
  15    children: React.ReactNode;
  16  }) {
  17    const commandPalette = useCommandPalette();
  18  
  19    return (
  20      <CommandPaletteContext.Provider value={commandPalette}>
  21        {children}
  22      </CommandPaletteContext.Provider>
  23    );
  24  }
  25  
  26  // eslint-disable-next-line react-refresh/only-export-components
  27  export function useCommandPaletteContext() {
  28    const context = React.useContext(CommandPaletteContext);
  29    if (!context) {
  30      throw new Error(
  31        "useCommandPaletteContext must be used within CommandPaletteProvider"
  32      );
  33    }
  34    return context;
  35  }
  36