我正在尝试根据react原生渲染视图中的一些条件移动到另一个屏幕。
export default class Home extends React.Component {
constructor() {
super();
}
render(){
if(this.state.num == "yes"){
return(this.props.navigation.navigate("Homepage"))
}
else{
return null;
}
}
}
这会将我移动到下一个屏幕,也就是Homepage
,但它会给出一个警告。
ReactNativeJS: Warning: Cannot update during an existing state transition (such as within
renderor another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to 'componentWillMount'.
有没有办法解决这个警告。我很想知道这件事。谢谢
发布于 2018-08-25 00:27:49
尝试在componentDidUpdate
方法中运行该逻辑,该方法在呈现之后运行
https://stackoverflow.com/questions/52008371
复制相似问题