Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda