"TypeError: Object(...) is not a function" react-redux-firebase

"TypeError: Object(...) is not a function" react-redux-firebase

我正在尝试在 React 中创建一个项目,并且我正在使用 Firebase。在我的 react-redux-firebase 项目中,一行代码出错但我无法修复。我该如何解决这个“TypeError: Object(...) is not a function”

我已经搜索过这个问题,但无法解决问题。

我正在学习 react 版本为 16.4.1 的教程。我不确定这是不是问题所在

index.js 文件

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import { createStore, applyMiddleware, compose } from "redux";
import rootReducer from "./store/reducers/rootReducer";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import { reduxFirestore, getFirestore } from "redux-firestore";
import { reactReduxFirebase, getFirebase } from "react-redux-firebase";
import fbConfig from "./config/fbConfig";

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

if I comment out the reatReduxFirebase() then it works fine but I need this to work

You could find all codes here: https://github.com/martuza-shimul/React-Blog-app

我每次都收到这个错误:

TypeError: Object(...) is not a function
Module../src/index.js
i:/Learning new things/react/pma/src/index.js:17
  14 | const store = createStore(
  15 |   rootReducer,
  16 |   compose(
> 17 |     applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
  18 |     reduxFirestore(fbConfig),
  19 |     reactReduxFirebase(fbConfig)
  20 |  

我不确定如何解决这个问题。一点点help/hint真是感激不尽

请使用这个 npm 包
npm 包兼容性问题

npm i --save react-redux@5.1.1 react-redux-firebase@2.2.4

这是一个 react-redux-firebase v2.x.x 编码模式,您可能已经安装了 v3.x.x。

  1. 检查您使用的是哪个版本的 react-redux-firebase:
    npm ls react-redux-firebase
  1. 如果版本为 3.0.0 或更高,您需要将代码迁移到新的编码模式。有关详细说明,请参阅 React-Redux-Firebase v3.x.x Migration Guide

reactReduxFirebase store enhancer 在 v3 及以上版本中被移除。您现在可以使用上下文提供程序创建 firebase 实例。现在可以这样做:

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

const rrfProps = {
firebase,
config: fbConfig,
dispatch: store.dispatch
}

const App = () => (
  <Provider store={store}>
    <ReactReduxFirebaseProvider {...rrfProps}>
      <Todo />      // your Component
    </ReactReduxFirebaseProvider>
  </Provider>
 );

截至目前,'reduxFirestore' 工作正常,所以我想保持原样,但我认为未来几天也会发生同样的情况。因此,最好省略 compose 和 reduxFirestore(fbConfig) 而是使用:

import { createFirestoreInstance } from 'redux-firestore'

并将 createFirestoreInstance 添加到 rrfProps,如下所示:

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

更多信息结帐:http://react-redux-firebase.com/docs/v3-migration-guide.html#remove-createFirebaseConnect-and-createFirestoreConnect

Option 01- adjust npm package versions for react-redux & react-redux-firebase

npm install react-redux@5.1.1 react-redux-firebase@2.2.4

Option 02- Refer v3 ( http://react-redux-firebase.com/docs/v3-migration-guide.html )