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

188
Visualizações
Filter array in React

I am trying to filter an array using Chakra UI. But the filtering cannot be done correctly. I have done many tests to make sure that if the problem is in other codes, I can say that the problem is caused by the code below. However, I can share more code with you if you want.

Note: The list disappears when the filterText exists, and the listing works correctly when the filterText does not exist. This code belongs to a note taking app. I want to filter the notes that are already listed, not show the notes outside the filter.

I deployed it => https://take-notesw.surge.sh/

return (
     <Grid templateColumns="repeat(3, 1fr)" gap={6} marginTop="2">
         {
             filterText &&
             Array(notes).filter(note =>
                 note.title?.toLocaleLowerCase()
                     .includes(filterText)
                     .map(filteredNote => (
                         <Box
                             key={filteredNote.id}
                             bg="gray.100"
                             w="100%"
                             h="100px"
                             overflow="auto"
                             textAlign="center"
                         >
                             <Text fontSize="18px" bg={handleNoteColor(filteredNote.color)}>Note {filteredNote.id}</Text>
                             <Text fontSize="13px">{filteredNote.title}</Text>
                         </Box>
                        ))
                )
         }
         {
             !filterText &&
             notes.map((note) => (
                 <Box
                     key={note.id}
                     bg="gray.100"
                     w="100%"
                     h="100px"
                     overflow="auto"
                     textAlign="center"
                 >
                     <Text fontSize="18px" bg={handleNoteColor(note.color)}>Note {note.id}</Text>
                     <Text fontSize="13px">{note.title}</Text>
                 </Box>
          ))
      }
  </Grid >
)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You've got a misplaced parentheses. You're missing a ) after the includes and have instead placed that extra ) after the map.

return (
     <Grid templateColumns="repeat(3, 1fr)" gap={6} marginTop="2">
         {
             filterText &&
             Array(notes)
               .filter(note =>  
                     note.title?.toLocaleLowerCase().includes(filterText)
               )
               .map(filteredNote => (...))
         }
         {
             !filterText &&
             notes.map((note) => (...))
         }
  </Grid>
)
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