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

160
Views
React How to Update State Object Value in State Using SetState

I am trying to update a single object value (boolean) in my array using setState. Based on previous discussions, my approach does not mutate prior state, creates a copy of the original array, updates the copy, and then updates the original array. The 'issue' I have run into is that while the state updates my virtual list, the array does not re-render (FlatList in RN, specifically).

Previous Discussions Referenced: React: how to update state.item[1] in state using setState?

As a work around, I make a copy of my original array and then set the original array to empty. The cost is a very brief 'flicker' whenever the array re-renders.

Question: Is there a better way to update an object's value in my array AND trigger a re-render of the array elsewhere in my application?

Current Solution:

originalArray = [{ id: '123', randomKey: true }, {'234', randomKey: false }, ...]

const index = originalArray.findIndex(item => item.id === currentItemId)
if (index > -1) {
   const newArray = [...originalArray]
   setOriginalArray([]) // My solution to re-render the array
   let updatedItem = {...newArray[index]}
   updatedItem.randomKey = !randomKey // the value is a boolean
   newArray[index] = updatedItem
   setOriginalArray(newArray)
}

Cheers!

about 4 years ago · Juan Pablo Isaza
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!