これは初めてReact Nativeを使用していて、簡単にReduxで作業しましたが、私はRedux/authentication.js
にFirebaseで新しいアカウントを作成するはずの機能を持っています。React Native Reduxでインポートされた関数をディスパッチする
export function handleAuthWithFirebase (newUser) {
return function (dispatch, getState) {
dispatch(authenticating());
console.log(newUser);
console.log('Signing up user');
var email = newUser.email;
var password = newUser.password;
firebase.auth().createUserWithEmailAndPassword(email, password).catch(error => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
}).then(() => {
var user = firebaseAuth.currentUser;
// Set user in Firebase
firebase.database().ref('/users/' + user.uid).set({
displayName: newUser.displayName,
userName: newUser.userName,
email: newUser.email
})
})
dispatch(isAuthed(user.uid))
}
}
私はいくつか<TextInput/>
年代のユーザー情報を取得するSignUpFormコンポーネントにこの機能をインポートします。だから私はhandleSignUp
関数を実行したいと思っていますが、私はどのように完全にはわかりません。
class SignUpForm extends Component {
static propTypes = {
}
state = {
email: '',
password: '',
username: '',
displayName: ''
}
handleSignUp() {
// Want to call handleAuthWithFirebase(this.state) here.
}
render() {
console.log(this.props);
return (
<View style={{flex: 1}}>
<View>
<TextInput
style={styles.input}
onChangeText={(email) => this.setState({email})}
value={this.state.email}
autoCorrect={false}
/>
<TextInput
style={styles.input}
onChangeText={(password) => this.setState({password})}
value={this.state.password}
autoCorrect={false}
/>
<TextInput
style={styles.input}
onChangeText={(username) => this.setState({username})}
value={this.state.username}
autoCorrect={false}
/>
<TextInput
style={styles.input}
onChangeText={(displayName) => this.setState({displayName})}
value={this.state.displayName}
autoCorrect={false}
/>
</View>
<View>
<Button title="Sign Up" onPress={this.handleSignUp}>Sign Up</Button>
</View>
</View>
)
}
}
export default connect()(SignUpForm)
私console.log(this.props)
が、私がしようとするとhandleSignUp
方法でthis.props.dispatch(handleAuthWithFirebase(this.state))
を行うときに、私は小道具エラーを取得するにはundefined
dispatch
が小道具として使用可能であることを私に示しています