【发布时间】:2020-12-03 07:15:42
【问题描述】:
我现在很困惑。学习 js 前端以及如何发出 API 请求。
到目前为止,每当我进行 API 调用时,我总是使用一些东西来处理异步请求(axios 或 thunk)。
但现在我遇到了一个案例,我正在向我的 Firebase/Firestore 发出请求,并且在我观看的 yt 视频中,只使用了 useEffect。没有任何async/await,比如:
useEffect(() => {
// snapshot - to check, if there is a change (like a new entry) in the database
db.collection('products').onSnapshot((snapshot) => {
setProducts(snapshot.docs.map((doc) => doc.data()));
});
}, []);
这是为什么?
【问题讨论】:
标签: javascript reactjs axios react-hooks