How to integrate redux into firebase firestore?

Viewed 65

I am able to get the data in categoryMap from firebase firestore but I want to save the data in a state and then share that state between components using redux toolkit. Should I create action creators in the code below or should I use react's useState hook and then apply redux on top of that?

Here is the code snippet of the data I get from firestore:

export const getCategoriesAndDocuments = async () => {
  const collectionRef = collection(db, 'categories');
  const q = query(collectionRef);
  const querySnapshot = await getDocs(q);
  const categoryMap = querySnapshot.docs.reduce((acc, docSnapshot) => {
    const { title, items } = docSnapshot.data();

    acc[title.toLowerCase()] = items;
    return acc;
  }, {});
};
1 Answers

You can directly store your data in your redux store. Since redux store is A store holds the whole state tree of your application you don't need to add an extra state.

Related