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

109
Visualizações
Get to array in react state

I am using redux for state management on react-native and I am a total rookie, be warned ;)

I am converting my static data to using the product state instead of an array.

This is my static product array which will later be fetched from an API.

    const products = [
       {id: 1, title: 'Apple Pie'},
    ];

On app load I set the state like this:

    useEffect(() => {
      dispatch(allActions.productActions.setProducts(products))
    },[]);

On my view I call the getItem function, which works fine with the static array

    function getItem(itemId) {
      let obj = products.filter(item => item.id === itemId);
      return obj[0];
    }

the function returns an undefined object error, because it expects the actual array and not the state object.

The products state looks like that:

 [{"products":[{"id":1,"title":"Apple Pie"}]}]

out of that I need:

[{"id":1,"title":"Apple Pie"}]
about 4 years ago · Santiago Trujillo
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