Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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 answers
Answer question

0

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

{
  ...state, [action.row]: action.payload
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!