nandorojo / swr-firestore

Implement Vercel's useSWR for querying Firestore in React/React Native/Expo apps. 👩‍🚒🔥

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use multiple where condition when one of them is "not-in" or "!="

agungkes opened this issue · comments

I'm trying to use two where conditions where one of them is "not-in" or "! =".
But i get this error "Cannot read property forEach of null" in use-swr-collection.ts

this is my sample code

const { data, loading, error } = useCollection<Profile>('users', {
    listen: true,
    where: [
      ['uid', '!=', profile!.uid],
      ['school', '==', profile!.school],
    ],
  });

and I am trying to solve this problem by adding a check in querySnapshot

previous

querySnapshot => {
          const data: Doc[] = []
          querySnapshot.forEach(doc => {

after

 querySnapshot => {
        if (querySnapshot !== null) {
          const data: Doc[] = []
          querySnapshot.forEach(doc => {

I don't know if that's the best way or not

Thank you for your hard work

What if you do this:

const { data, loading, error } = useCollection<Profile>(profile ? 'users' : null, {

Thank you for your fast response.

I've tried using the code you suggested, but I still get the error Cannot read property forEach of null

Are you sure this isn't happening due to you looping through data.forEach instead of data?.forEach?

Please submit a code sandbox reproduction.