Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
Problem with filtering the search bar on next.js with firebase

Im building a chat app using next.js and firebase.The problem is that im trying to build a search bar that filters by the email of the user.The filter only works for emails that are in the 0 index of the array.Any clues? The users array contains the users that are in the chat The array of the doc looks like this: enter image description here

   const [searchTerm,setSearchTerm]=useState("");
   const [user]=useAuthState(auth)
   const userChatRef=db.collection('chats').where('users','array-contains',user.email)
   const[chatsSnapshot]=useCollection(userChatRef) 
   render( 
    <Search>
        <SearchIcon/>
        <SearchInput
        style={{fontFamily:"Roboto",fontSize:"calc(6px + 0.3vw)"}}
        type="text"
        placeholder="Pesquise uma conversa"
        onChange={(event) => {
            setSearchTerm(event.target.value);
        }}
    />
    </Search>
    {chatsSnapshot?.docs.filter((user)=>{
     
        console.log(user.data().users.findIndex(email =>email !== user.email ))
        if(searchTerm==""){
            return user
        } else if (user.data().users[user.data().users.findIndex(email =>email !== user.email )].toLowerCase().includes(searchTerm.toLowerCase())){
            
            return user
            
        }
    }).map((chat)=>(
        <Contact key={chat.id}>
           <Chat  id={chat.id} users={chat.data().users}></Chat>
           <Line/>
        </Contact>
        
        
    ))}
 )
const Search=styled.div`
display: flex;
align-items: center;
padding:5px;
border-radius:2px;
height:60px;
background-color:#f1f2f6;
border-radius:5px;
`;

const SearchInput= styled.input`
outline-width:0;
border:none;
flex:1;
font-size:15px ;
margin-left:10px;
background-color:#f1f2f6;
min-width:10vh;
font-size:calc(3px + 0.5vw);
font-family: 'Roboto';
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda