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

152
Visualizações
How do i update object in redux

I would like to update an object in the middle of processing redux I need to check if this is first time for a function.

here is my code.

const initialState = {
  table: [],
  timer: 0,
  result: "",
  gameState: false,
  openedCount: 0,
  isFirst: true
};

what I tried

if(state.isFirst) {
   state.isFirst = false;
}

How do I update like that in redux? just want to update for isFirst not returning state.

I will return { ...state, table: newArray }

I would really appreciate your help thanks for reading my question.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can write this condition :

if(state.isFirst) {
   state.isFirst = false;
}

in each switch case : and update your state accordingly .

For example :

const initialState = {
  table: [],
  timer: 0,
  result: "",
  gameState: false,
  openedCount: 0,
  isFirst: true
};
const Reducer(state=initialState,action)=>{
   switch(action.type){
      case "first" : 
           if(state.isFirst) {
              state.isFirst = false;
              // update the new state
           }       
      case "second" : 
           if(state.isFirst) {
              state.isFirst = false;
              // update the new state
           }   
      default : return;        
   }
}
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