我试图根据某些条件从我的渲染视图中的响应本机移至另一个屏幕
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'.
是否有解决此警告的方法。我将不胜感激。谢谢
答案 0 :(得分:0)
尝试在componentDidUpdate
方法中运行该逻辑,该方法在渲染之后运行