Why am I getting the following error while trying to create a store with redux-toolkit?
Uncaught TypeError: setting getter-only property "configureStore"
This is my scr/store/index.js
:
import { configureStore } from "@reduxjs/toolkit";
import uiSlice from "./ui-slice";
const store = configureStore = ({
reducer: {
ui: uiSlice.reducer
}
})
export default store;
And this is my src/index.js
import ReactDOM from 'react-dom/client';
import { Provider } from 'react';
import './index.css';
import App from './App';
import store from './store/index';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<Provider store={store}>
<App />
</Provider>
);
I’ve followed redux-toolkit
documentation as I did previously in other projects and I never had this error before. Am I omitting something?
3
Answers
Maybe it is because of not putting redux
import { Provider } from ‘react-redux’;
this line:
const store = configureStore = ({
is either some new JS syntax that I don’t know or a syntax error.
try this:
configureStore
is a function you’ve imported but are trying to overwrite the value. It should be called, e.g.const store = configureStore({ .... });
.Provider
is also imported fromreact-redux
, notreact
.