Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在React中调用Firebase HTTPS可调用云函数_Javascript_Reactjs_Firebase_Google Cloud Functions - Fatal编程技术网

Javascript 在React中调用Firebase HTTPS可调用云函数

Javascript 在React中调用Firebase HTTPS可调用云函数,javascript,reactjs,firebase,google-cloud-functions,Javascript,Reactjs,Firebase,Google Cloud Functions,所以,我正在做一个React项目,它使用Firebase来实现许多功能。 现在我尝试在其中使用一些HTTPS可调用函数 但我导入“firebase/functions”模块的方式似乎不正确。这给了我一个错误: TypeError: Cannot read property 'httpsCallable' of undefined 以下是我如何进行导入和设置: import app from 'firebase/app'; import 'firebase/auth'; import 'fire

所以,我正在做一个React项目,它使用Firebase来实现许多功能。 现在我尝试在其中使用一些HTTPS可调用函数

但我导入“firebase/functions”模块的方式似乎不正确。这给了我一个错误:

TypeError: Cannot read property 'httpsCallable' of undefined
以下是我如何进行导入和设置:

import app from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/functions';

const config = {
   // the config info here
};

  class Firebase {
    constructor() {
      app.initializeApp(config);
      this.auth = app.auth();
      this.db = app.firestore();
      this.functions = app.functions();
    }

    // trying to call the function
    doCreatePlanner = this.functions.httpsCallable('createPlanner')

有人能给我指出正确的方向吗?

在构造函数中定义此函数之前,您正在尝试访问它。要消除错误消息,可以将对
httpscalable
的调用移动到构造函数中:

    constructor() {
      app.initializeApp(config);
      this.auth = app.auth();
      this.db = app.firestore();
      this.functions = app.functions();
      const doCreatePlanner = this.functions.httpsCallable('createPlanner')
    }

这可能不是您想要做的,但无论如何,在您定义它之前,您不能使用
这个.functions

谢谢Doug!你的建议对我有用。但我还是有点困惑。你能看看最新的问题吗?评论太长了如果你还有其他问题,应该单独发布,而不是添加到原始内容上。改变问题的性质实际上会使给定的答案无效,并且对将来的其他人没有帮助。正确。我的错。我将提出另一个问题。