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

245
Views
How to fix the error "Invalid hook call. Hooks can only be called inside of the body of a function component." in next js

I want to fetch data from my data from firebase database with uesEffect hook but it gives an error message that Error: Invalid hook call. Hooks can only be called inside of the body of a function component. How can i fix this any advice.Thanks in advance. My code is here

     useEffect(()=>{
            console.log("session",session)
        },[session]);
    
        const [myChats]=useCollection(db.collection('chats').where('users','array-contains',session.user.email));
    
        useEffect(()=>{
          myChats?.docs?.map((user)=>{
            setMyChat((prevState)=>[...prevState,user.id])
            useCollection(db.collection('chats').doc(id).collection('messeges').orderBy('timestamp','asc').limitToLast(1)).then(function(chat){
                console.log("chat",chat.id);
                setChats((prev)=>[...prev,chat]);
            })
        })
      },[myChats]);
        
       //   useEffect(()=>{
 // chats?.map((chat,i)=>{
 //     
 //        console.log("id",chat.id);
 //        console.log("photo",chat.data().photoURL);
 //        console.log("email",chat.data().user);
 //        console.log("chat",chat.data().message)
 //    })
 //    },[myChats])
         console.log("myChat",chats)
             
       
       
    
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!