reactjs - 为什么不能对未安装的组件执行 React 状态更新?
问题描述
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。
解决方案
推荐阅读
- c++ - 当前的草案是否允许形成一个重载集,该集由两个非静态成员声明组成,其中一个具有引用限定符
- r - 如何减少 R 中 SQL 查询的错误?
- python - 当用户输入的数字前面只有一个减号 (-) 时,如何仅将 if 用于数字
- tensorflow - 如何将许多 numpy 数组发送到 sagemaker 端点
- reactjs - 如何在服务器端渲染中更改 BrowserRouter
- c# - 获取 WSUS 更新大小 (PowerShell)
- c# - CreateDelegate() System.ArgumentException 方法签名不匹配
- r - 编织 RMarkdown 文件时发生错误
- php - 加载资源失败:在生产服务器laravel上使用ajax发送post请求时服务器响应状态为403
- tomcat - 我如何部署我的 apache tomcat 服务器,因为我不能这样做