reactjs TypeError:prevDeps.join不是下一个js函数

z9ju0rcb  于 2023-01-25  发布在  React
关注(0)|答案(1)|浏览(548)

我想在next js和firebase中创建一个搜索栏,它的工作原理是从url中获取slug,然后通过我的搜索算法解析它,问题是如果用户使用搜索栏2次,它就会中断并显示以下错误:

我就是这样把数据

<Link  href={`http://localhost:3000/search/${search}/`} >
                <Magnify fontSize='small' />
              </Link>

这就是我如何得到它

const serachId = router.query.id;
    useEffect(() => {
        onAuthStateChanged(auth, async (user) => {

            if (user) {
                // User is signed in, see docs for a list of available properties
                // https://firebase.google.com/docs/reference/js/firebase.User
                const places = query(collection(getFirestore(app), '/programs'))
                const querySnapshot = await getDocs(places)


                querySnapshot.docs.forEach(doc => {

                    if (JSON.stringify(doc.data()).includes(router.query.id)) {
                        let programObj = {
                            age: doc.data().price,
                            icon: doc.data().logo,
                            status: "software",
                            date: doc.data().start,
                            name: doc.data().name,
                            salary: '$$$',
                            email: doc.data().website,
                            designation: 'Human Resources Assistant',
                            id: doc.id
                        };
                        setPrograms(prev => [...prev, programObj]);
                    }
                })
            }
            else {
                console.log("no loggin")
            }
        });

    }, router.query.id)
pobjuy32

pobjuy321#

依赖项数组应放在方括号[ ]中
例如:[router.query.id]

相关问题