【发布时间】:2018-03-15 13:41:11
【问题描述】:
我的属性 isLoading 是一个布尔 on 状态,我检查它以确定我的渲染代码的主体是否已准备好执行,或者应该等待一个旋转的加载器。当我在调试器中检查状态时,isLoading 应该是一个布尔值,但是当我进一步检查 isLoading 时,它是未定义的。这是在同一个断点内(除了将鼠标悬停在 1 秒后的另一个属性上之外,我什么也没做)。这真的把我的代码弄乱了,因为 isLoading 属性在它下面的 if 语句中是未定义的,因此它不会等待我的代码准备好。谁能告诉我为什么我的 isLoading 属性是未定义的,即使当我查看状态时它是一个布尔值??
render() {
const {isLoading} = this.state.isLoading;
if (isLoading) {
return (<Loader isVisible={true}/>);
}
【问题讨论】:
-
您的意思可能是
const { isLoading } = this.state。您当前的代码正在寻找不存在的this.state.isLoading.isLoading。 -
const {isLoading} = this.state
-
要么删除
{}并使用const isLoading = this.state.isLoading要么 使用这个:const {isLoading} = this.state
标签: javascript reactjs react-native