Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda