Actually my problem is that I want to add a light mode dark mode feature for my next js application using redux toolkit.
In _app.js if adding like this
<ThemeProvider theme={theme}>
<CssBaseline />
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</ThemeProvider>;
It’s showing an error called:
Error:
could not find react-redux context value; please ensure the component is wrapped in a
<Provider>
If I put only provider application is working but I need theme provider also, How can I Use Redux toolkit with material ui theme provider in next js
[Error] CodeI want to add a light mode dark mode feature for my next js application using redux toolkit and material ui theme provider how can i wrap both in _app.js.
2
Answers
Something similar happened to me since I am also using "nextJs 13-MUI-Redux tolkit", this is how I solved it.
I am working with the app folder so I have a page.tsx, layout.tsx and template.tsx, here is layout and template:
and the template component:
You will need to create HOC first and then use it to wrap around Nextjs Component.
and then you can use above HOC as following