首页 > 解决方案 > React configureStore2.default.firestore 不是一个函数

问题描述

我很抱歉打开这篇文章 - 我知道还有其他人。我可能已经从其他帖子中尝试了 20 种不同的设置组合,但我无法通过它。任何帮助将不胜感激。

我收到此错误:

configureStore2.default.firestore 不是函数

动作文件:

import firebase from '../store/configureStore';
.....

export const setTweets = (tweets) => ({
    type: 'SET_TWEETS',
    tweets
  });

  export const startSetTweets = () => {
    return (dispatch, getState) => {
      const uid = getState().auth.uid;
      console.log("uid = ", uid);
     
      const postsRef = firebase
        .firestore()          //  <---- this line causes the error
        .collection("posts");

从配置商店

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

firebase.initializeApp(firebaseConfig)
  firebase.firestore().settings({ timestampsInSnapshots: true }) 

.......

 export { googleAuthProvider, firebase, store as default} 

来自 package.json

 "firebase": "^8.1.1",

    "redux": "3.7.2",
    "redux-firestore": "0.14.0",

标签: javascriptreactjsgoogle-cloud-firestore

解决方案


您似乎正在导入默认导出configureStorestore但它看起来像您想要的firebase那样。

如果是这种情况import { firebase } from '../store/configureStore';,请在您的操作文件中使用。

所以你的代码会这样:

import { firebase } from '../store/configureStore';
// .....

export const setTweets = (tweets) => ({
    type: 'SET_TWEETS',
    tweets
  });

  export const startSetTweets = () => {
    return (dispatch, getState) => {
      const uid = getState().auth.uid;
      console.log("uid = ", uid);
     
      const postsRef = firebase
        .firestore()
        .collection("posts");

在此处阅读有关命名导出的更多信息:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export


推荐阅读