Reactjs 如何从另一个类刷新React Native中的主应用程序类呈现
我正在尝试使用React Native创建我的第一个应用程序, 我已经创建了一个类来呈现身份验证表单,在处理提交之后,应用程序应该呈现带有选项卡的导航屏幕。我想我可以通过某种方式刷新身份验证屏幕上的应用程序类呈现,这样它就可以再次检查用户是否进行了身份验证,但我并不确定 App.Js:Reactjs 如何从另一个类刷新React Native中的主应用程序类呈现,reactjs,react-native,Reactjs,React Native,我正在尝试使用React Native创建我的第一个应用程序, 我已经创建了一个类来呈现身份验证表单,在处理提交之后,应用程序应该呈现带有选项卡的导航屏幕。我想我可以通过某种方式刷新身份验证屏幕上的应用程序类呈现,这样它就可以再次检查用户是否进行了身份验证,但我并不确定 App.Js: import AuthScreen from './screens/AuthScreen'; export default class App extends React.Component { state
import AuthScreen from './screens/AuthScreen';
export default class App extends React.Component {
state = {
isLoadingComplete: false,
isAuthenticated: false,
};
render() {
if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
return (
<AppLoading
startAsync={this._loadResourcesAsync}
onError={this._handleLoadingError}
onFinish={this._handleFinishLoading}
/>
);
} else {
if(this.state.isAuthenticated == true) {
return (
<View style={styles.container}>
<StatusBar hidden = {true} />
<AppNavigator />
</View>
);
} else {
return (
<View style={styles.container}>
<StatusBar hidden = {true} />
<AuthScreen />
</View>
);
}
}
}
AuthScreen.js:
export default class AuthScreen extends Component {
handleSubmit = () => {
const value = this._form.getValue();
console.log('value: ', value);
}
render() {
return (
<View style={styles.container}>
<View style={styles.auth_container}>
<Form
ref={c => this._form = c}
type={User}
options={options}
/>
<Button
title="Submit"
onPress={this.handleSubmit}
/>
</View>
</View>
);
}
}
您可以使用react navigationRN导航库来实现这一点。但根据问题代码,您尝试在屏幕之间切换
以您的方式:如果成功,请手动提交AuthScreen方法
handleSubmit = () => {
check auth logic
this.props.onSuccessFullLogin(value)
}
更新ParentComponent中的状态以在屏幕和应用程序组件之间切换:
这应该是这样的。setState{isAuthenticated:true}}/>您可以使用react导航,Link导航相同的内容