Skip to content

Instantly share code, notes, and snippets.

@khusamov
Last active March 5, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khusamov/58da3cebde3913aacf3e0b4fdfd48b70 to your computer and use it in GitHub Desktop.
Save khusamov/58da3cebde3913aacf3e0b4fdfd48b70 to your computer and use it in GitHub Desktop.
Решение проблемы типа 'Providers Hell'
import React, {FunctionComponent, ReactElement, Fragment, cloneElement} from 'react';
/**
* Решение проблемы типа 'Providers Hell'.
* @link https://gist.github.com/khusamov/58da3cebde3913aacf3e0b4fdfd48b70
*/
const ApplicationProviders: FunctionComponent<{providers: ReactElement[]}> = (
({children, providers}) => {
return (
[...providers, <Fragment>{children}</Fragment>]
.reverse()
.reduce((result, provider) => cloneElement(provider, {children: result}))
);
}
);
export default ApplicationProviders;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment