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

171
Views
Too many rerednders error by trying to show a FlatList

I am trying to display a flatList of numbers like this : (image of what the flat list would look like) To do that I did an array of objects with a numberName and a key, it's generating with a loop:

const number = 5;

let [numbers, setNumbers] = useState([]);

let nums = [];
for (let i = 0; i < number; i++) {
nums.push({ numberName: i, key: i });

console.log(nums)
}
setNumbers((numbers) => [...numbers, ...nums]);

I dont think the problem is in the loop, but react is recalling the loop without showing the component. This makes an infinite loop and I have the too Many rerender error.

Here is what console.log(nums) shows (screenshot of the console)

and here is how i am trying to render the array :

if(!fontsLoaded) {return <AppLoading />} 
else {return (
    <View>
        <FlatList
            showsHorizontalScrollIndicator={false}
            horizontal={true}
            data={numbers} //la data qu'on va afficher
            renderItem={({ item }) => (
                <Text style={styles.number}>{item.numberName}</Text>
            )} //la fonction qu'il va rendre
        />
    </View>
)}

Why do I have the too many rerenders error and how do I fix it ?

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

0

let [numbers, setNumbers] = useState([]);
useEffect(()=>{
const nums = numbers.map((value,index)=> {numberName: index,key: index})
setNumbers([...numbers, ...nums])
},[])

You need to do assignment/state-related stuff inside useEffect hook.

about 4 years ago · Juan Pablo Isaza Report

0

For taking in account changes in states, you'll need to make it with useState hook, like this:

    const number = props.numberProp;

    let [numbers, setNumbers] = useState([]);

    useEffect(() => {    
    let nums = [];
        for (let i = 0; i < number + 100; i++) {
        nums.push({ numberName: i, key: i });
        }
    setNumbers((numbers) => [...numbers, ...nums]);
    }, [])

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!