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

267
Views
In Firebase v9, how can I filter clothes list items by category title or default to all?

I'm working on an app and I am trying to allow a user to filter items based on a category titles or view all. With this code, I able to get all the items that have been added by a given user, but I'd like to be able to filter by category as well, and show all the items if no category is selected.

export const ClothingListItems = ({ category }) => {
  const [items, setItems] = useState([]);
  const userUid = auth.currentUser.uid;
  const [isLoading, setIsLoading] = useState(false);
  const [isError, setIsError] = useState(false);

  //getting items where closetceator Uid == userUid
  const getClosetAsync = async ({category}) => {
    setIsLoading(true);
    try {
      const q = query(
        collection(db, "clothing"),
        where("closetOwerUid", "==", userUid)
      );

      onSnapshot(q, (snapshot) => {
        let results = [];
        snapshot.forEach((doc) => {
          results.push({ ...doc.data(), id: doc.id });
        });
        setItems(results);
        setIsLoading(false);
      });
    } catch (error) {
      setIsError(error.message);
    }
  };

  // Keep track with changes in data add or delete. Clean up!
  useEffect(() => {
    const unsubscribe = getClosetAsync();
    return () => unsubscribe;
  }, []);

  return isLoading ? (
    <LoadingIndicator />
  ) : isError || !items.length ? (
    <>
      <Error />
      <EmptyView message="Your closet is empty, add items." marginSize={65} />
    </>
  ) : (
    <View style={styles.container}>
      <>
        <FlatList
          data={items}
          keyExtractor={(item) => item.id}
          numColumns={2}
          renderItem={({ item }) => <ClothingItem items={item} />}
        />
      </>
    </View>
  );
};

database

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!