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

291
Vistas
How to modify state in reducer.js to cause re-render of component?

There is a component down the line that uses hash but it's not re-rendering every time there is a change in the value of state.hash. How do I modify this code in reducer.js so that when state.hash is updated, the component that uses it is re-rendered from scratch?

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


const counterSlice = createSlice({
  name: 'counter',
  initialState: {
    hash: null,
    d: null,
  },
  reducers: {
    update: (state, {payload}) => {
      const {hash, d} = payload
      state.hash = hash
      state.d = d
    }
  }
})

export const {update} = counterSlice.actions

export const {reducer: counterReducer} = counterSlice

Alternatively, how do I change this code that calls the reducer to achieve the same effect?

  store.dispatch(update({hash, d: d.toString()}))
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the useEffect hook to listen for changes to a variable in state and re-render the component when it changes.

useEffect(() => {
  console.log(hash)
},[state.hash])

Reference

about 4 years ago · Juan Pablo Isaza Denunciar
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