import React, { Dispatch, PropsWithChildren, useMemo } from 'react'; import { DescendantsList } from './Descendants.types'; import { DescendantContextType } from './DescendantsContext'; import { DescendantsReducerAction } from './DescendantsReducer'; export interface DescendantsProviderProps { context: DescendantContextType; descendants: DescendantsList; dispatch: Dispatch>; } /** * The provider for descendants context values. * * Receives a specific context value as `context` * in order to have multiple nested descendant contexts * * Also receives a `descendants` list in order to ensure the outer parent * has access to the descendants object */ export const DescendantsProvider = ({ context, children, descendants, dispatch, }: PropsWithChildren>) => { const Provider = context.Provider; const providerValue = useMemo( () => ({ descendants, dispatch, }), [descendants, dispatch], ); return {children}; };