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

147
Views
How to avoid re rendering in react native?

I'm trying to avoid re-rendering unnecessary components
For example:

const[ValueState,SetValueState]=useState(5); //hook

<View>
 <Text>{ValueState}</Text>
 <View>
  {
   [...Array(3)].map((index,el)=>{
    return (<View><Text>Hello there</Text></View>)
   })
  }
 </View>
</View>

here every time I change the value of ValueState the entire map() segment also gets re-rendered
how do I avoid this and make the map() segment only render 1 time?

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

0

It depends on what the function you don't want to re-render depends on. In this case, your array and map function do not depend directly to ValueState.

One way to achieve 1 re-render is using React.memo

Example to render map function only once

import React, { useState } from "react";
import { View, Text, TouchableOpacity } from "react-native";



const ArrayMapSection = React.memo(()=> {
  console.log("ArrayMapSection rendered")
  return  [...Array(3)].map((index,el)=>{
    return (<View><Text>Hello there</Text></View>)
   });
})

const App = () => {
const [ValueState,SetValueState]=useState(5); //hook

return(
<View>
 <Text>{ValueState}</Text>

 <TouchableOpacity onPress={()=>SetValueState(Math.random())}>Press to state update</TouchableOpacity>
 <View>
  <ArrayMapSection />
 </View>
</View>

)


};

export default App;

If you run this program, you would see ArrayMapSection renderedonly once in the console. Now try to change the ValueState by pressing on Press to state update. The ArrayMapSection won't re-render because React.memo only re-renders if props changes

More info: https://reactjs.org/docs/react-api.html#reactmemo

about 4 years ago · Juan Pablo Isaza Report

0

Create a custom react component that takes the array as a prop and maps it to other components.

That way the component is only rerenderd if the array prop changes.

Code example:

const[ValueState,SetValueState]=useState(5);

<View>
 <Text>{ValueState}</Text>
 <CustomList array={[1,2,3]} />
</View>

export const CustomList = (array) => {
    return (
        <>
          {
            array.map((index,el)=>{
                return (<View><Text>Hello there</Text></View>)
            })
          }
        <\>
    )
}
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!