TypeError: firestore.collection is not a function (React ,Redux, Firestore)

TypeError: firestore.collection is not a function (React ,Redux, Firestore)

将 firebase 和 firestore 与 React 集成时,我遇到了这个错误。

我遵循了新的 react-redux-firebase 文档,但没有帮助。

错误 -> 类型错误:firestore.collection 不是函数

这是我出错的函数

代码

export const addProductFamily = (productFamilyDetails) => {
  return (dispatch, getState, { getFirestore }) => {
    console.log("product family details ", productFamilyDetails);
    const firestore = getFirestore();
    console.log("firestore is ", firestore);
    firestore
      .collection("productFamilyDetails") <------------ error
      .add({
        ...productFamilyDetails,
      })
  };
};

这是我设置所有配置的 App.js 文件

App.js

import { Provider } from "react-redux";
import { createStore, applyMiddleware, combineReducers, compose } from "redux";
import thunk from "redux-thunk";
import authReducer from "./store/reducers/auth";
import {
  ReactReduxFirebaseProvider,
  firebaseReducer,
  getFirebase,
} from "react-redux-firebase";
import {
  createFirestoreInstance,
  firestoreReducer,
  getFirestore,
  reduxFirestore,
} from "redux-firestore";
import { firebaseConfig } from "./config/fbConfig";
import firebase from "firebase/app";

const rrfConfig = { userProfile: "users", useFirestoreForProfile: true };

const rootReducer = combineReducers({
  auth: authReducer,
  firebase: firebaseReducer,
  firestore: firestoreReducer,
});

const store = createStore(
  rootReducer,
  compose(
    applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
    reduxFirestore(firebaseConfig, firebase)
  )
);

const rrfProps = {
  firebase,
  config: rrfConfig,
  dispatch: store.dispatch,
  createFirestoreInstance,
};

ReactDOM.render(
  <Provider store={store}>
    <ReactReduxFirebaseProvider {...rrfProps}>
      <BrowserRouter>
        {/* <App /> */}
        <Layout />
      </BrowserRouter>
    </ReactReduxFirebaseProvider>
  </Provider>,
  document.getElementById("root")
);

我删除了不必要的导入

您调用 reduxFirestore 时参数倒过来了。改变这个:

reduxFirestore(firebaseConfig, firebase)

对此:

reduxFirestore(firebase, firebaseConfig)