我从一个单独的文件调用一个函数(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';
为什么 i 收到错误"(0, _firebase3.default) 不是函数?
提前致谢
您正在导出命名函数。将导入语句更改为
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;