Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
redux reducer... + 1 I have created a new array and added one. now how do I put it back together and return the new state

This almost works but its not updating the ui.... so found the index of what I want to change, I created a new array newFavorites and increased a value on one of its keys (sets +1). But I am not sure how to return the new state with the updated key value.

here is the model. i just want to add one to the sets

class Exercise {
    constructor(id, name, gifUrl, equipment, sets=4){
        this.id = id;
        this.name = name;
        this.gifUrl = gifUrl;
        this.equipment = equipment;
        this.sets = sets;

    }
}

export default Exercise;


    const initialState = {
        favoritedExercises: [],
    
    }
            case ADD_SETS: 
           const index= state.favoritedExercises.findIndex(fav => fav.id === action.payload.id);
           let newFavorites = [...state.favoritedExercises];
            newFavorites[index].sets + 1;
          
            
           
           
          return {
              ...state,
            favoritedExercises: newFavorites
          }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

for anyone else who might have this missunderstandiing..

case ADD_SETS: 
               const index= state.favoritedExercises.findIndex(fav => fav.id === action.payload.id);
               let newFavorites = [...state.favoritedExercises];
                newFavorites[index].sets = newFavorites[index].sets + 1;
                console.log(newFavorites[index])
              
            
           
           
          return {
              ...state,
            favoritedExercises: newFavorites
          }
            
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda