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,我会看看那篇文章。你知道为什么这不起作用吗?