反应本地组件调用firebase函数

时间:2019-01-27 02:02:30

标签: firebase react-native

我从另一个文件中调用函数(signUpUser),如下所示:

   <MyButton
            onPress={() =>
              signUpUser(
                this.state.userName,
                this.state.email,
                this.state.password,
              )
            }
          >

在我名为firebase.js的单独文件中,功能如下:

export const signUpUser = (userName, email, password) => {
  Firebase.auth()
    .createUserWithEmailAndPassword(email, password)
    .then((user) => {
      Firebase.database()
        .ref('profiles/users/' + user.user.uid)
        .set({
          .....etc
        });
    })
    .catch(err => Alert.alert(err));
};

Im导入如下:

import signUpUser from '../firebase';

为什么我遇到错误“”(0,_firebase3.default)不是函数?

预先感谢

1 个答案:

答案 0 :(得分:3)

您正在导出一个命名函数。将导入语句更改为

import {signUpUser} from '../firebase';

或者,如果需要,您可以将导出语句更改为默认导出

  const signUpUser = (userName, email, password) => {
  Firebase.auth()
    .createUserWithEmailAndPassword(email, password)
    .then((user) => {
      Firebase.database()
        .ref('profiles/users/' + user.user.uid)
        .set({
          .....etc
        });
    })
    .catch(err => Alert.alert(err));
}; 

export default signUpUser;