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

150
Views
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 answers
Answer question

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