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

131
Visualizações
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 Respostas
Responde à pergunta

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 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