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

153
Visualizações
Can I change the value of a property inside a redux state using a value passed in during the action call by the user?

I am trying to change the redux state, which is an object, but the property of the object that needs to be changed depends upon what the user wants to change. The state has properties in it that represent different rows in a table, and since there are a lot, I cant have a specific case for each one. So for example, instead of saying I want to change row1, I want to change action.row.

Here's some code of how it would be normally:

case 'CHANGE_STATE': {
      return {
        ...state, row1: action.payload
      }
    }

And here's an example of how I want it to work

case 'CHANGE_STATE': {
      return {
        ...state, action.row: action.payload
      }
    }

Where action.row is provided when calling the redux action.

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

0

You can use variables as object keys using a bracket notation:

{
  ...state, [action.row]: action.payload
}
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