import { createContext, Dispatch } from 'react'; import { DescendantsList } from './Descendants.types'; import { DescendantsReducerAction } from './DescendantsReducer'; export interface DescendantsContextProps { descendants: DescendantsList; dispatch: Dispatch>; } export type DescendantContextType = React.Context< DescendantsContextProps >; /** * A factory function that creates a new Context object. * The returned Context object will be used to define which context a descendant is a part of. */ export const createDescendantsContext = ( displayName?: string, ): DescendantContextType => { const context = createContext>({ descendants: [], dispatch: () => {}, }); context.displayName = displayName ?? 'DescendantsContext'; return context; };