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

125
Views
Firebase TypeError: Cannot read properties of null (reading 'indexOf')

When I console.log(docSnap) I'm getting a firebase error, see in the below image. I have tried all the solutions but none of them worked.

Firebase error

useEffect(() => {
        if (folderId === null) {
            dispatch({
                type: "UPDATE_FOLDER",
                payload: { folder: ROOT_FOLDER }
            })
        }
        // otherwise fetch from database

        const getdocSnap = async () => {
            const docRef = doc(db, "folders", folderId);
            return await getDoc(docRef);
        }
        const docSnap = getdocSnap();
        console.log(docSnap);

        if (docSnap.exists()) {
            dispatch({
                type: "UPDATE_FOLDER",
                payload: { folder: { id: docSnap.id, ...docSnap.data() } }
            })
        } else {

            console.log("No such document!");
            dispatch({
                type: "UPDATE_FOLDER",
                payload: { folder: ROOT_FOLDER }
            })
        }

    }, [folderId])

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How the problem solved ?

Ans: Created an async function callFunc & pasted all my logic inside it & called it.

Try the code below

useEffect(() => {
        if (folderId === null) {
            return dispatch({
                type: "UPDATE_FOLDER",
                payload: { folder: ROOT_FOLDER }
            })
        }
        // otherwise fetch from database
        const callFunc = async () => {
            const docRef = doc(db, "folders", folderId);
            const docSnap = await getDoc(docRef);

            if (docSnap.exists()) {
                dispatch({
                    type: "UPDATE_FOLDER",
                    payload: { folder: { id: docSnap.id, ...docSnap.data() } }
                })
            } else {

                console.log("No such document!");
                dispatch({
                    type: "UPDATE_FOLDER",
                    payload: { folder: ROOT_FOLDER }
                })
            }
        }

        callFunc();

    }, [folderId])

about 4 years ago · Juan Pablo Isaza Report
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!