import { getKeys } from "@daybrush/utils" ; import { Context , createElement , ReactNode , useContext , useEffect , useRef } from "react" ; export interface ContextConsumersProps < T extends Record < string , Context < any > > > { contexts : T ; children : ( value : { [ key in keyof T ] : T [ key ] extends Context < infer U > ? U : never ; } ) => ReactNode ; } export default function ContextConsumers < T extends Record < string , Context < any > > > ( props ) { const contexts = props . contexts ; const keys = getKeys ( contexts ) ; const obj = { } ; return keys . reduce ( ( cur , key ) => { return createElement ( contexts [ key ] . Consumer , null , ( value ) => { obj [ key ] = value ; return cur || props . children ( obj as any ) ; } ) ; } , null ) ; }