我正在尝试根据我在 react native 中的渲染视图中的某些条件移动到另一个屏幕
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
渲染or 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'.
有没有办法解决此警告。我很感激知道。谢谢
尝试在componentDidUpdate
方法中运行该逻辑,该方法在渲染后运行