nestable-dropdown-context.tsx 664 B

12345678910111213141516171819202122232425
  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<{ id: string }> = ({
  11. id,
  12. children,
  13. }) => {
  14. const [selected, setSelected] = useState<string | null>(null)
  15. return (
  16. <NestableDropdownContext.Provider
  17. value={{ selected, setSelected, menuId: id }}
  18. >
  19. {children}
  20. </NestableDropdownContext.Provider>
  21. )
  22. }