I have a login function that fetches the user info from mysql database. I want to send this data to different screens some of them are out of stack navigator. I was researching for a while and got to know that this could be done using redux, but i could not find a clear example on how to achieve that. Any suggestion on how to do that?
Here is my login function:
login = () => {
if (this.state.inputFieldsStatus == true)
{
// this.setState({passwordError:" Something went wrong! "})
fetch('http://ip_Adress/login', {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
// alert(JSON.stringify(res.message));
if (res.success === true ) {
// AsyncStorage.setItem('user', res.user);
this.props.navigation.navigate('Home',
// {
// screen: 'Messages',
// params:
// {
// message: res.message,
// otherParam: 'anything you want here'
// }
// },
{
screen: 'Profile',
params:
{
message: res.message,
otherParam: 'anything you want here'
}
}
);
} else {
this.setState({passwordError: res.message })
// alert(res.message);
}
})
.done();
}
else
{
// alert(' Please fill in all fields! ');
this.setState({passwordError:" Please fill in all fields! "})
}
}