import { createContext, Dispatch, FC, SetStateAction, useEffect, useState, } from 'react' export type NestableDropdownContextType = { selected: string | null setSelected: Dispatch> menuId: string } export const NestableDropdownContext = createContext< NestableDropdownContextType | undefined >(undefined) export const NestableDropdownContextProvider: FC< React.PropsWithChildren<{ id: string }> > = ({ id, children }) => { const [selected, setSelected] = useState(null) useEffect(() => { return () => { // unset selection on unmount setSelected(null) } }, []) return ( {children} ) }