Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Last active October 29, 2019 00:07
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 helloncanella/39ad21cedd3eef0f67c0606545087019 to your computer and use it in GitHub Desktop.
Save helloncanella/39ad21cedd3eef0f67c0606545087019 to your computer and use it in GitHub Desktop.
import React from "react"
import _ from "lodash"
/**
* Provided that a list of providers [P1, P2, P3, P4] is passed as props,
* it renders
*
* <P1>
<P2>
<P3>
<P4>
{children}
</P4>
</P3>
</P2>
</P1>
*
*/
export default function ComposeProviders({ Providers, children }) {
if (_.isEmpty(Providers)) return children
return _.reverse(Providers)
.reduce((acc, Provider) => {
return <Provider>{acc}</Provider>
}, children)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment