An Interest In:
Web News this Week
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
August 28, 2021 07:59 am GMT
Original Link: https://dev.to/hyposlasher/no-more-react-context-hell-4pm3
No More React Context Hell
If you always wanted it to look like this
<Providers providers={[ <FooContext.Provider value="foo" />, <BarContext.Provider value="bar" />, <BazContext.Provider value="baz" />, ]}> <App /> </Providers>,
here is your Providers Component:
const Providers = ({providers, children}) => { const renderProvider = (providers, children) => { const [provider, ...restProviders] = providers; if (provider) { return React.cloneElement( provider, null, renderProvider(restProviders, children) ) } return children; } return renderProvider(providers, children)}
Enjoy!
Like, share and etc
Original Link: https://dev.to/hyposlasher/no-more-react-context-hell-4pm3
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To