Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 即使仍然假定要渲染组件,也会评估React道具_Reactjs_React Context - Fatal编程技术网

Reactjs 即使仍然假定要渲染组件,也会评估React道具

Reactjs 即使仍然假定要渲染组件,也会评估React道具,reactjs,react-context,Reactjs,React Context,我的组件有一个包装器,告诉它们在完成加载之前不要渲染,就像这样 从“React”导入React; 从“vivid.react.components/atoms/LoadingSpinner”导入LoadingSpinner; 类包装器扩展了React.Component{ componentDidMount(){ this.props.getInitialState(); } render(){ const{error,isLoadingInitialState}=this.props; 返回

我的组件有一个包装器,告诉它们在完成加载之前不要渲染,就像这样

从“React”导入React;
从“vivid.react.components/atoms/LoadingSpinner”导入LoadingSpinner;
类包装器扩展了React.Component{
componentDidMount(){
this.props.getInitialState();
}
render(){
const{error,isLoadingInitialState}=this.props;
返回(
{!!错误&&error:{error.message}
{isLoadingInitialState
? 
:儿童
}
)
}
};

导出默认包装器这是
包装器的完整代码吗?
isLoadingInitialState
的初始值是多少?我假设isLoadingInitialState的初始值等于undefined。对不起,我修复了代码。isLoadingInitialState的初始值在Screen的父级中设置为true,并通过上下文向下传递。问题是ChildComponent道具的价值在Wrapper的渲染方法之前就已经评估过了,我不知道为什么@Yucheng Lin会有更好的解决方案——你可以尝试使用HigherOrderComponent。看看@AravindS,我会看看那篇文章。你知道为什么这不起作用吗?