Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
ReactJS Redux state persisting after being reset

Basically I got a state called optimizer in which I store a field named optimizer_course_entries , this field has 2 reducers on it:

import { createSlice } from "@reduxjs/toolkit";

const initialState = {
    optimizer_course_entries : [],
}

export const optimizerSlice = createSlice(
    {
        name: 'optimizer',
        initialState,
        reducers: {
            edit_entry: (state, action) => {
                console.log('CALLED EDIT REDUCERS');
                state.optimizer_course_entries[action.payload.index] = action.payload.value;
            },
            reset: (state) => {
                console.log('CALLED RESET REDUCER');
                state.optimizer_course_entries = [];
            }

        }
    }
)

export const {edit_entry, reset} = optimizerSlice.actions;

export default optimizerSlice.reducer;

In my react app, I have a call to edit_entry everything a textbox is edited, and it sends the index and value in a payload to Redux.

  const receiveChange = (Value, Index) => {

    dispatch(edit_entry({
        index : Index,
        value : Value,
      }));
  }

I have the reset reducer set on component mount like this:

    React.useEffect(
    () => {

      dispatch(reset());

    } , [] 
  )

The issue i'm having is that on component mount, instead of redux only doing a reset, it also restores previous reducer actions..

issue

And in my redux store, the optimizer_course_entries entry is identical to before the reset...

I'm still pretty new to redux, is there a way I can specify it so that upon re-mount it doesn't do this repopulation?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!