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

188
Vistas
Calling setState inside of FlatList renderItem
function ABC({ navigation }){

    const [localItemID, setLocalItemID] = useState();


    const dataToSelect = useSelector((state) => state.posts.postsData);

    return(
        <View>
            <FlatList data={dataToSelect} keyExtractor={(item, index) => {return index.toString()}} renderItem={({item}) => {
                setLocalItemID(item._id);
                
                return(
                    <TouchableOpacity>
                        <Image source={logo} />
                        <Text>{item.name}</Text>
                    </TouchableOpacity>
                );
            }} />
        </View>
    );

}

when I add this line:

 setLocalItemID(item._id);

in the function of the renderItem prop in FlatList, I get the following error:

Warning: Cannot update a component (%s) while rendering a different component (%s). To locate the bad setState() call inside %s, follow the stack trace as described in https://reactjs.org/link/setstate-in-render%s, ListComponent, CellRenderer, CellRenderer, in CellRenderer (created by VirtualizedList)

about 4 years ago · Juan Pablo Isaza
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