私は反応ネイティブと解析サーバーを使用しています。私は、ユーザー登録を実施していますが、このエラーが表示されます。メソッドが状態を読み取ることができません
未定義のは(「this.state.username」を評価)
オブジェクトされていない状態がクラス全体に読まれるべきではありませんか?
import React, {Component} from 'react';
import {Container, Content, Form, Item, Input, Button, Text} from 'native-base';
var Parse = require('parse/react-native');
export default class Singup extends Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: ''
};
}
Buttonpress() {
Parse.initialize("APPLICATION_ID");
Parse.serverURL = 'http://***.***.**.**:1337/parse'
var user = new Parse.User();
user.set("username", this.state.username);
user.set("password", this.state.password);
user.signUp(null, {
success: function(user) {
console.warn("YES");
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
}
render() {
return (
<Container>
<Content>
<Form>
<Item>
<Input
placeholder="Username"
onChangeText={(text) => this.setState({username: text})}
value = {this.state.username}/>
</Item>
<Item last>
<Input
placeholder="Password"
onChangeText={(text) => this.setState({password: text})}
value = {this.state.password}/>
</Item>
</Form>
<Button
block
onPress={this.Buttonpress}>
<Text>Inscrever-se</Text>
</Button>
</Content>
</Container>
);
}
}
自動的に翻訳されます。
あなたの関数の結合
[SETSTATE再利用可能に反応](https://stackoverflow.com/questions/41887440/react-の可能性のある重複setstate-reusable) –
ButtonPress関数とのバインディングの問題は、重複を参照してください –
この質問はその作成者によって放棄されました。正解はありませんでした。 –