Like the callback hell, usual when jQuery was used for everything, the React Context hell is the nasty code you get taking advantage of the React Context API.
constApp=()=>{// ... some codereturn (<><ReduxProvidervalue={store}><ThemeProvidervalue={theme}><OtherProvidervalue={otherValue}><OtherOtherProvidervalue={otherOtherValue}>{/** ... other providers*/}<HellProvidervalue={hell}><HelloWorld/></HellProvider>{/** ... other providers*/}</OtherOtherProvider></OtherProvider></ThemeProvider></ReduxProvider></>)}
How to fix it?
To clean up the nasty code you get from taking advantage of React Context API we need a way to nest multiple Context.Provider without passing them as children of each other.
Clone and return a new React element using element as the starting point. The resulting element will have the original element’s props with the new props merged in shallowly. New children will replace existing children. key and ref from the original element will be preserved.
We can use the cloneElement API to reduce a collection of providers, this way we don't have to nest them inside each other.
So you don't use react router and have a BrowserRouter in your code? Or if you use CSS in JS solution, you don't have a kind of ThemeProvider? Or you put both in a recoil state?
Ah and you still need the RecoilRoot, a provider.
Good point to alert context hell!
I simple skip use context, instead works with simple useReducer, and pass down actions and state in props. That way give more simple component, because my component don't have outer dependency - expect props, so easy join together in quite complex app.
Why is it better?