Created
June 29, 2021 14:50
-
-
Save AitorAlejandro/fe7ff4777adb4aaf43c305a9934cb0d4 to your computer and use it in GitHub Desktop.
Avoid Context Hell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReactDOM.render( | |
<Provider3> | |
<Provider2> | |
<Provider1> | |
<App /> | |
</Provider1> | |
</Provider2> | |
</Provider3>, | |
rootElement | |
); | |
// becomes into | |
export default function ContextProviders({ children }) { | |
return ( | |
<Provider3> | |
<Provider2> | |
<Provider1> | |
{children} | |
</Provider1> | |
</Provider2> | |
</Provider3> | |
); | |
} | |
// using as this | |
import ReactDOM from "react-dom"; | |
import ContextProviders from './context/ContextProviders' | |
import App from "./App"; | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render( | |
<ContextProviders> | |
<App /> | |
</ContextProviders>, | |
rootElement | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment