我已经使用POST API进行了登录验证,我收到了成功的响应,内部成功响应,我只想导航到其他屏幕说例如(从登录屏幕到视频屏幕)。但它不适合我请看看我的代码并告诉我我在哪里犯了错误。
index.android.js:
export default class Registration extends Component {
render() {
const { navigation } =this.props;
return (
<Login navigation={ navigation }/>);
}
}
src/Login.js:
class Login extends Component {
constructor(props) {
super(props);
this.redirect=this.redirect.bind(this)
this.state = {
email: '',
password: '',
errors: '',
}
}
On button submit i just calling below method
CallSignIn() {
fetch("http://localhost:3000/users/login", { method: "POST", body: JSON.stringify({ email: this.state.email, password: this.state.password }), headers: { 'x-api-key': '7LH9ElCr4p1GLiMXAWLu0a9UsvKZ4wJr7t1N3ewh', 'Content-Type': 'application/json' } })
.then((response) => response.json())
.then((responseData) => {
this.setState({ showProgress: false })
this.redirect()
Alert.alert("success:", JSON.stringify(responseData.token));
})
.done();
}
redirect() {
const { navigate } = props.navigation;
navigate('Videos')
}
}