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

126
Views
Function won't update value into nested array

I'm currently displaying an array into a SectionList in React Native, I'm trying to update in real-time the value selected, this is the array:

Array [
  Object {
    "data": Array [
      Object {
        "id": 1.01,
        "price": 1,
        "selected": false,
        "title": "Ranch",
        "type": "Sides",
      },
      Object {
        "id": 1.02,
        "price": 1,
        "selected": false,
        "title": "Blue Cheese",
        "type": "Sides",
      },
    ],
    "required": false,
    "type": "Sides",
  },
  Object {
    "data": Array [
      Object {
        "id": 2.01,
        "price": 1,
        "selected": false,
        "title": "Hot Sauce",
        "type": "Sauces",
      },
      Object {
        "id": 2.02,
        "price": 1,
        "selected": false,
        "title": "Medium Sauce",
        "type": "Sauces",
      },
    ],
    "required": true,
    "type": "Sauces",
  },
]

this is the function I'm using to update the array:

const pressOptional = (e) => {    
      additional.map((item) => {
        if (item.type == e.type) {
          item.data.map((a => {
            if (a.id == e.id) {
              a.selected = !e.selected
            }
          }))
        }
      })
    }

I'm calling this function in a button displayed in the SectionList, and when I call it, I see it changing the value, but the SectionList still reads the previous data

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You forgot to return the mapped value.

const pressOptional = (e) => {    
     return additional.map((item) => {
        if (item.type == e.type) {
          item.data.map((a => {
            if (a.id == e.id) {
              a.selected = !e.selected
            }
          }))
        }
      })
    }
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!