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

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

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 Denunciar

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