nestable-dropdown-context.tsx 688 B

123456789101112131415161718192021222324
  1. import { createContext, Dispatch, FC, SetStateAction, useState } from 'react'
  2. export type NestableDropdownContextType = {
  3. selected: string | null
  4. setSelected: Dispatch<SetStateAction<string | null>>
  5. menuId: string
  6. }
  7. export const NestableDropdownContext = createContext<
  8. NestableDropdownContextType | undefined
  9. >(undefined)
  10. export const NestableDropdownContextProvider: FC<
  11. React.PropsWithChildren<{ id: string }>
  12. > = ({ id, children }) => {
  13. const [selected, setSelected] = useState<string | null>(null)
  14. return (
  15. <NestableDropdownContext.Provider
  16. value={{ selected, setSelected, menuId: id }}
  17. >
  18. {children}
  19. </NestableDropdownContext.Provider>
  20. )
  21. }