Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!