I am having troubles creating a redux store for React website. How do I create the store here?
The error:
Uncaught Invariant Violation: (app/utils...) injectors: Expected a valid redux store
at invariant
....
The above error occurred in the <HomePage> component:
at HomePage (http://localhost:3000/static/js/src_containers_HomePage_index_js.chunk.js:232:5)
at ConnectFunction (http://localhost:3000/static/js/bundle.js:51172:68)
at Suspense
at Routes (http://localhost:3000/static/js/bundle.js:54041:5)
at IntlProvider (http://localhost:3000/static/js/bundle.js:50235:43)
at ParallaxProvider
.....
at Router (http://localhost:3000/static/js/bundle.js:53974:15)
at BrowserRouter (http://localhost:3000/static/js/bundle.js:53449:5)
at Provider (http://localhost:3000/static/js/bundle.js:50883:20)
I am using react-router-dom v6.
src/index.js:
import React from 'react';
import { hydrateRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { BrowserRouter } from "react-router-dom";
import { createStore } from 'redux'
import rootReducer from './reducers'
const store = createStore(rootReducer, window.__PRELOADED_STATE__)
if (typeof window === 'object') {
const container = document.getElementById("root");
hydrateRoot(container,
<React.StrictMode>
<Provider store={store}>
<BrowserRouter>
<App />
...
I recommend you to use redux-toolkit , it is easier to learn and use , and much less code is written with it ,the code provided is not enough.