Javascript 反应本机传递值
我是React Native的新手,我在谷歌上搜索过,但我只能找到React Native的旧版本 实际上,我不知道如何将状态值传递给其他js文件 我正在制作Authpage,如果状态值“isValid”变为“true”,它将重定向到tappage.js 我正计划在App.js上这样更改页面,如果有其他更好的方法,请告诉我 谢谢这是我的密码。 AuthManager.jsJavascript 反应本机传递值,javascript,react-native,Javascript,React Native,我是React Native的新手,我在谷歌上搜索过,但我只能找到React Native的旧版本 实际上,我不知道如何将状态值传递给其他js文件 我正在制作Authpage,如果状态值“isValid”变为“true”,它将重定向到tappage.js 我正计划在App.js上这样更改页面,如果有其他更好的方法,请告诉我 谢谢这是我的密码。 AuthManager.js export default class AuthPage extends Component { constructo
export default class AuthPage extends Component {
constructor(props) {
super(props);
this.state = {
user : null,
firebaseUser : null,
fcmToken : null,
accessToken : null,
authType : null,
hasInitialNotification : null,
isValid : false
};
this.unsubscribe = null;
}
...some codes..
render() {
// if (!this.state.firebaseUser) {
return (
<Provider store={store}>
<View style = {styles.main}>
<View style ={styles.logotemp}>
<Image style ={styles.logo}
source={require('../../resources/logo/logo.png')}
/>
</View>
<View style = {styles.inputid}>
<FormInput
ref={(el)=> {this.email = el;}}
textInputRef='email'
placeholder = "Email"
onChangeText={(email) => this.setState({email})}
value = {this.state.email}
/>
<FormInput
ref={(el)=> {this.password = el;}}
textInputRef='password'
onChangeText={(password) => this.setState({password})}
value = {this.state.password}
placeholder = "Password"
secureTextEntry = {true}
/>
<TouchableOpacity onPress={this._emailSignIn.bind(this)}>
<Image
style = {styles.loginbut}
source={require('../../resources/socialicon/signin.png')}
/>
</TouchableOpacity>
</View>
<View style = {styles.socialicons}>
<TouchableOpacity onPress={this._facebookSignIn.bind(this)} >
<Image
style={styles.fbicons}
source={require('../../resources/socialicon/facebook.png')}
/>
</TouchableOpacity>
<Image
style={styles.divider}
source = {require('../../resources/socialicon/divider.png')}
/>
<TouchableOpacity onPress={this._googleSignIn.bind(this)} >
<Image
style={styles.ggicons}
source={require('../../resources/socialicon/google.png')}
/>
</TouchableOpacity>
</View>
</View>
</Provider>
);
// }
if (this.state.firebaseUser) {
return(
<Provider store = {store}>
{store.isValid = this.state.isValid}
</Provider>
);
}
}
export default class MainPage extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
render() {
alert(store.isValid);
if(!this.props.isValid){
return(<View style={{flex:1}}>
<AuthPage></AuthPage>
</View>
);
}
if(isValid){
return(
<View style={{flex:1}}>
<TabPage></TabPage>
</View>
);
}
}
}
导出默认类AuthPage扩展组件{
建造师(道具){
超级(道具);
此.state={
用户:null,
firebaseUser:null,
fcmToken:null,
accessToken:null,
authType:null,
hasInitialNotification:null,
isValid:false
};
this.unsubscribe=null;
}
…一些代码。。
render(){
//如果(!this.state.firebaseUser){
返回(
{this.email=el;}}
textInputRef='email'
占位符=“电子邮件”
onChangeText={(email)=>this.setState({email})}
值={this.state.email}
/>
{this.password=el;}}
textInputRef='password'
onChangeText={(密码)=>this.setState({password})}
值={this.state.password}
占位符=“密码”
secureTextEntry={true}
/>
);
// }
if(this.state.firebaseUser){
返回(
{store.isValid=this.state.isValid}
);
}
}
导出默认类主页面扩展组件{
建造师(道具){
超级(道具);
}
componentDidMount(){
}
render(){
警报(store.isValid);
如果(!this.props.isValid){
返回(
);
}
如果(有效){
返回(
);
}
}
}
谢谢 React中的习惯用法是只有当前元素才能知道它的状态。 我强烈建议使用用于组件之间的全局数据传输,或者,如果不需要数据同步,可以使用