0

    const [business, setBusiness] = useState({});

const fetchData = async() => {
    const response= firebase.firestore().collection('Business');
    const data = await response.doc(id).get().then((doc) => {
        if (doc.exists) {
            console.log("Document data:", doc.data());
            setBusiness(doc.data())
        } else {
            // doc.data() will be undefined in this case
            console.log("No such document!");
        }
    }).catch((error) => {
        console.log("Error getting document:", error);
    });
    })
  }

    useEffect(()=>{
        console.log("here")
        fetchData().then(
            ()=>{
                //Dispatch data to the Redux Store..
            }
        ).then(
            dispatch(setLoading(false))
        )
    },[business])

我这里有一个从 Firestore 数据库获取数据的方法,另一方面是一个 useEffect,它首先触发该fetchData()方法,然后将数据分派到我的 Redux 存储,最后将加载程序设置为 false。

4

0 回答 0