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

152
Visualizações
Change array object value in react native with textInput and function component

Hello guys I wanna ask about change Array Value when I type in text input in react native

const [rad, setRad] = useState([
  { value: 'a', status: false, title: 'ab },
  { value: 'b', status: false, title: 'ac' },
  { value: 'c', status: false, title: 'ad' },
]);


<TextInput 
  numberOfLines={2} 
  placeholder="note"
  onChangeText={(text) => setRad([...rad[3], { value: text }])}
/>

but when I type an error screen comes up and the message 'Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method'

What should I do?

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

0

The initial state is an array of length 3, i.e. with indices 0, 1, and 2, so attempting to spread ...rad[3] is the code attempting to spread the fourth element, which is an undefined value.

You likely meant to spread the previous rad state array instead into the new array reference and append the new text value. When updating arrays in React state it's recommended to use a functional state update to ensure updating from the previous state and not the value of state closed over in any callback/handler scopes.

<TextInput 
  numberOfLines={2} 
  placeholder="note"
  onChangeText={(text) => setRad(rad => [...rad, { value: text }])}
/>
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