Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

104
Visualizações
Component inside renderList in a FlastItem remounting after calling setState

I'm passing a component to the renderItem. Inside the component I have a state and i make a call to the api that will update this state with the response.

But what is happening is, it renders loading... then it actually shows what the api returned, goes back to showing loading and then goes back to showing what the api returned.

For example: if the searchDescriptionById function returns description 1, what is rendering on the screen is: loading... -> description 1 -> loading... -> description 1

as if at the first setState the component is remounting


const Component= ({ item }) => {
      const [description, setDescription] = useState('loading...');
      useEffect(() => {
        searchDescriptionById(item.id).then(res => {
          setDescricao(res);
        })
      }, [])
      return (
          <TouchableOpacity style={{ flex: 1 }}>
            <Textbold>{item.id}</Text>
            <Text>{description}</Text>
          </TouchableOpacity>
      )
  }

<FlatList
 data={data}
 contentContainerStyle={{ paddingBottom: 10 }}
 keyExtractor={item => item.id}
 renderItem={({item}) => <Component item={item}/>}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda