react-context-hooks-example
react-context-hooks-example copied to clipboard
How to manage multi context?
First thanks for your example. How to manage multi context:
- Articles
- Posts
- Comments
- Tasks
- ...
Could example?
I down't want to use Nested Provider, and could use each others
function App() {
return (
<ArticleProvider>
< Posts />
// Others Provider
<Component />
</Posts>
</ArticleProvider>
);
}
Hi and sorry for the delay, you can share your code (repo) with me please, in order for me to check it, and I'll show you how to handle multiple contexts.
thanks for your reply. for example I have many context
- Articles
- Posts
- Comments
- Tasks
And then I will config its on App startup
function App() {
return (
<ArticleProvider>
< PostsProvider />
< CommentProvider />
............
<App />
< CommentProvider />
</PostsProvider>
</ArticleProvider>
);
}
It is not good to config, if we have many contexts!!!!!
After finding npm package, I found https://github.com/VeprUA/react-multi-provider to config multi contexts like this
<MultiProvider
providers={[
<ContextProvider1/>,
<ContextProvider2/>,
<ContextProvider3/>,
...
]}>
<SomeComponent/>
</MultiProvider>
But I still problem on share context each others.
For example We can't use ContextProvider1 in ContextProvider2, 3
Please help me...