0
私は反応ネイティブの反応ナビゲーションを使用しています。私がrender()
作品の中でthis.props.navigation.dispatch (resetAction)
を呼び出すと。すでにButtonpress()
の中にあります。私の目標は、Parse Serverがユーザーを認証してルートをリセットするときに別のルートに移動することです。メソッド内でreact bind resetActionを使用するにはどうすればよいですか?
自動的に翻訳されます。あなたはそれが別のコンテキスト内だから、それはどこか、どこthis != this
から呼び出されますので、現在のコンテキストにあなたの機能をbind
する必要が
import React, {Component} from 'react';
import {Container, Content, Form, Item, Input, Button, Text} from 'native-base';
var Parse = require('parse/react-native');
import {NavigationActions} from 'react-navigation'
const resetAction = NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({routeName: 'Main'})]
})
export default class Auth extends Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: ''
};
this.Buttonpress = this.Buttonpress.bind(this);
}
static navigationOptions = {
title: 'Hedone'
};
Buttonpress() {
Parse.initialize("APPLICATION_ID");
Parse.serverURL = 'http://192.168.25.18:1337/parse'
Parse.User.logIn(this.state.username, this.state.password, {
success: function(user) {
// Do stuff after successful login.
() => this.props.navigation.dispatch(resetAction)
console.warn("Certo")
},
error: function(user, error) {
// The login failed. Check error to see why.
console.warn("Errado");
}
});
}
render() {
const {navigate} = this.props.navigation;
return (
<Container>
<Content>
<Form>
<Item>
<Input placeholder="Username" onChangeText={(text) => this.setState({username: text})}/>
</Item>
<Item last>
<Input placeholder="Password" onChangeText={(text) => this.setState({password: text})}/>
</Item>
</Form>
<Button block onPress={this.Buttonpress}>
<Text>Entrar</Text>
</Button>
<Button block onPress={() => navigate('Up')}>
<Text>Inscrever-se</Text>
</Button>
</Content>
</Container>
);
}
}
ありがとうございました! –