import * as React from 'react' ; import { IProvider , ProviderProps } from '../types' ; interface CombineProvidersProps extends ProviderProps { providers : Array < IProvider > ; } /**
 *
 * Component which take a list of providers and returns
 * a Provider which contain all those providers nested in it
 */ const CombineProviders = ( { children , providers , } ) => { if ( providers . length === 0 ) return < > { children } < />; const RootProvider = providers . reduce ( ( ProviderAccumulator , Provider ) => { return ( { children } ) => ( < ProviderAccumulator > < Provider > { children } < /Provider> < /ProviderAccumulator>); } ) ; return < RootProvider > { children } < /RootProvider>; } ; export default CombineProviders ;