【发布时间】:2020-04-07 08:53:58
【问题描述】:
我正在制作一个从 API 获取数据的验证表单。所以,我有一个名为“isLogged”的状态。
我将它初始化为 false,然后如果身份验证有效,它会更改为 true。
所以,我正在尝试使用 if 条件为 "isLogged" === true 呈现 if-else 语句,然后我应该将用户导航到仪表板页面
否则当“isLogged”为假时,我会渲染整个表单组件,
但我不知道如何在没有 onPress 或渲染组件的情况下在屏幕之间导航用户,我只是想调用一个函数来导航或其他东西
代码:
class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: null,
password: null,
isLogged: false,
}
}
render() {
if (this.state.isLogged) {
# the command which navigate the user to Dashboard page
} else {
return (
# The whole component code>
);
}
}
}
【问题讨论】:
-
你在哪里使用 setState 使
isLogged为真?
标签: reactjs react-native react-native-navigation