【问题标题】:React Native Cannot call a class as a functionReact Native 无法将类作为函数调用
【发布时间】:2020-12-30 15:19:18
【问题描述】:

我有一个简单的功能,可以在 firebase 中注册用户并将数据保存在 cloud firestore 中

但我收到此错误:

[TypeError: 无法将类作为函数调用]

谁能帮我找出错误的位置?

下面的函数:

const handleSignUp = useCallback(
    async data => {
      try {
        setLoading(true);

        const auth = await authFB().createUserWithEmailAndPassword(
          data.email,
          data.password,
        );

        const db = firestore();

        const firstName = data.name.split(' ').slice(0, -1).join(' ');
        const lastName = data.name.split(' ').slice(-1).join(' ');

        await db
          .collection('Providers')
          .doc(auth.user.uid)
          .set({
            id: auth.user.uid,
            name: {
              first: firstName,
              last: lastName,
            },
            email: data.email,
            createdAt: firestore.Timestamp.fromDate(new Date()),
            address: {
              position: firestore.GeoPoint(
                coordinates.latitude,
                coordinates.longitude,
              ),
            },
          })
          .then(() => {
            navigation.reset({
              routes: [{ name: 'SignIn' }],
              index: 0,
            });
          });

        setLoading(false);

        Alert.alert(
          'Cadastro realizado com sucesso!',
          'Você já pode fazer login na aplicação.',
        );
      } catch (err) {
          setLoading(false);
      }
    },
    [coordinates],
  );

【问题讨论】:

    标签: firebase react-native function google-cloud-firestore firebase-authentication


    【解决方案1】:

    我对 Firestore API 不是很熟悉,但很可能您在创建 GeoPoint 时只需要 new 关键字:

    position: new firestore.GeoPoint(
        coordinates.latitude,
        coordinates.longitude,
    ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-25
      • 2020-02-11
      • 2020-03-12
      • 2018-10-21
      • 2020-07-01
      • 2016-12-26
      • 2016-11-23
      • 1970-01-01
      相关资源
      最近更新 更多