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

275
Vistas
How to destructure redux state in react redux?

I am not getting the point of using ...in ...state. When I have watched a tutorial of react redux they mentioned that it is destructuring of state variable but can you explain me the point mentioned .

export const productreducer=(state=initialstate,{type,payload})=>{

switch(type)
 case ActionTypes.SETPRODUCTS:
     return{...state,...payload}; //here I have a doubt
 default:
     return state
}
};
   
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

So {...} refers to spread or expand out the iterable elements, Lets take an example, you cannot change the state directly in the redux store and therefore you need to make a copy and append the new payload to the state and return the state.

state={ x:1, y:2 } payload={ y:5 , z:6 }

{...state, ...payload} // { x: 1, y: 5, z: 6 }

This will update the old state to the new state.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Generally, assume you have

const a = { foo: 1, bar: 2 }

then the following two are equivalent:

return { foo: a.foo, bar: b.bar }

and

return { ...a }

so essentially, ... copies over all the elements from the old object into a new object.

That said, modern Redux doesn't do this. Modern Redux also does not do switch..case reducers, ACTION_TYPES or connect. You might have been following a very outdated tutorial.

I would really recommend you to follow the official Redux Essentials tutorial that will teach you modern Redux from the beginning - it's much safer against accidental errors and only a fourth of the code.

about 4 years ago · Juan Pablo Isaza Denunciar

0

It's Spread syntax. In your case, it gets all key: value pairs from objects and combines them into a new object. Hope with snippet it will be more clear

const state = {a: 1, b: 2}
const payload = {c: 3, d: 4}

const result = {...state, ...payload}
console.log(result)

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