skip to Main Content

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


  1. Maybe it is because of not putting redux

    import { Provider } from ‘react-redux’;

    Login or Signup to reply.
  2. this line: const store = configureStore = ({
    is either some new JS syntax that I don’t know or a syntax error.

    try this:

    const store = configureStore({
    reducer: {ui: uiSlice.reducer},
    });
    
    Login or Signup to reply.
  3. configureStore is a function you’ve imported but are trying to overwrite the value. It should be called, e.g. const store = configureStore({ .... });.

    import { configureStore } from "@reduxjs/toolkit";
    import uiSlice from "./ui-slice";
    
    const store = configureStore({
      reducer: {
        ui: uiSlice.reducer
      }
    });
    
    export default store;
    

    Provider is also imported from react-redux, not react.

    import ReactDOM from 'react-dom/client';
    import React, { StrictMode } from 'react';
    import { Provider } from 'react-redux';
    import './index.css';
    import App from './App';
    import store from './store';
     
    const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(
      <StrictMode>
        <Provider store={store}>
          <App />
        </Provider>
      </StrictMode>
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search