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

222
Visualizações
Why isn't .filter method doing anything in my Expo app?

I'm building an app with Expo and trying to apply a filter to fetchUsers function which pulls a list of Users from Database that are matched with the Authenticated User. I'm using AWS for backend. However, when I do fetchedUsers.filter it doesn't return ANY User card.

So I have a function fetchMatches which pulls all the Users that have matched with the Authenticated user like so:

useEffect(() => {
  if (!me) {
      return;
  }
  fetchMatches();

 }, [me]);

 const fetchMatches = async () => {
    const result = await DataStore.query(Match, match => 
      match
      .isMatch('eq', true)
      .or(match => match.matchUser1Id('eq', me.id).matchUser2Id('eq', me.id))
      );
  setMatches(result);
  console.warn(result);

}

Then I have a function fetchUsers which takes the matches and filters them down to the matches user ids and compares them to the fetched User ids and excludes them if the userId equals the matched User id so you don't have to swipe on somebody you've already matched with.

useEffect(() => {
  
  if(!isUserLoading && user) {
    fetchUsers();
  }
}, [me, matches, user]);

const fetchUsers = async () => {
  let fetchedUsers = await DataStore.query(User);
  
    setUsers(fetchedUsers.filter(user => {
      matches.filter(match => 
        match.matchUser1Id !== user.id && match.matchUser2Id !== user.id
      )
    }));
}

So when I apply this filter to fetchedUsers then NO User cards are returned to Homescreen. However, when I remove the filter and just do setUsers(fetchedUsers) it returns the entire array of Users from the Database. As of now, there aren't any unhandled promises showing up in console or any type of errors. It's just simply not rendering. And I'm using Expo. Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Don't use the nested filter(), use some() to perform a test. And you need to return that result, so don't put {} around it.

setUsers(fetchedUsers.filter(user =>
  matches.some(match =>
    match.matchUser1Id !== user.id && match.matchUser2Id !== user.id
  )
));

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