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

82
Visualizações
React native: Handling state with lots of data

I am making a simple social media app in React Native. In my Feed screen, I am fetching data from my API, storing the array of objects in a posts state, and using a Flatlist to render Post components. I have other screens like PostDetail that I navigate to when a Post is pressed.

The more complex my app gets the harder it gets to manage the posts state that contains all the data required to display posts in the Feed. I find it especially awkward to update that state from other screens like PostDetail; when a user likes the post, comments on the post, etc.

I tried using React's Context API to store posts as a "global" state. That way I had access to the posts state in every screen. But whenever I would update the state it caused the entire app to re-render. Another thing: I find that creating a new posts object is very inefficient when only 1 item needs to be updated. This comes from the notion that state should be immutable in React.

// what if 'posts' is an array of 100+ items? This seems inefficient
const updatedPosts = posts.map(post => (
   post.id === newPost.id ?
   {
      ...post,
      likes: newPost.likes,
      comments: newPost.comments
   } : post
));

setPosts(updatedPosts);

Is there a better way of handling states with lots of data? I've heard that Redux can solve problems like this, but I want to avoid using it unless I really need to.

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