【问题标题】:TypeError: Object(...) is not a function - I am lostTypeError: Object(...) is not a function - 我迷路了
【发布时间】:2019-12-04 23:06:41
【问题描述】:
INDEX.JS FILE

    import { compose, createStore, applyMiddleware } from 'redux';
    import thunk from 'redux-thunk';
    import firebase from '../Firebase/Firebase';
    import { reactReduxFirebase, getFirebase } from 'react-redux-firebase';
    import { reduxFirestore, getFirestore } from 'redux-firestore';

    import rootReducer from './reducers';

    // react-redux-firebase config
    const rrfConfig = {
      userProfile: 'users',
      useFirestoreForProfile: true, // Firestore for Profile instead of Realtime DB
    };

    const composeEnhancers =
      process.env.NODE_ENV === 'development'
        ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
        : compose;

    const store = createStore(
      rootReducer,
      composeEnhancers(
        reactReduxFirebase(firebase, rrfConfig),
        reduxFirestore(firebase),
        applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore }))
      )
    );
    export default store;

我相信我的格式是正确的,但是,我迷路了。有人可以帮忙吗?以下是我的 reducers 文件夹中的两个文件。如有任何问题,请随时提出,我会尽力回答。我被严重卡住了。


REDUCERS -> AUTHREDUCER.JS

const initialState = {

}

export default(state = initialState, action) => {
    return'dhdhdhd';
};

REDUCERS -> INDEX.JS

import {combineReducers} from 'redux';
import { firebaseReducer } from 'react-redux-firebase';

import authReducer from './authReducer';

export default combineReducers({
    auth: authReducer,
    firebase: firebaseReducer,
});`enter code here`

运行 NPM 启动时,我返回此错误:

"TypeError: Object(...) is not a function" at const store = createStore(.

【问题讨论】:

  • 我们可以查看您的reducers 文件吗?
  • const initialState = { } export default(state = initialState, action) => { return'dhdhdhd'; };
  • import {combineReducers} from 'redux'; import { firebaseReducer } from 'react-redux-firebase'; import authReducer from './authReducer'; export default combineReducers({ auth: authReducer, firebase: firebaseReducer, });
  • 我无法从您上面的两个 cmets 中分辨出这些是哪些文件。您能否编辑您的问题并添加带有文件名的代码
  • 感谢您指出这一点。我已经进行了修改,它们反映在上面。

标签: javascript reactjs firebase redux google-cloud-firestore


【解决方案1】:

checkout https://redux.js.org/api/createstore,我相信第二个参数应该是初始状态

const initialState = {} // the initial value for your state

const store = createStore(
  rootReducer,
  initialState, // 2nd argument of createStore is initial state
  composeEnhancers(
    ...
  )
);

更新:

checkout http://docs.react-redux-firebase.com/history/v3.0.0/docs/v3-migration-guide.html#remove-store-enhancer 因为他们已经弃用了 react-redux-firebase 的增强器

所以

  • 从增强器中移除 reactReduxFirebase
  • 使用ReactReduxFirebaseProvider
const rrfProps = {
  ...
};
const App = () => (
  <Provider store={store}>
    <ReactReduxFirebaseProvider {...rrfConfig}>
      ...
    </ReactReduxFirebaseProvider>
  </Provider>
);

【讨论】:

  • 不幸的是,这不起作用。我添加了 const initialState = {} 并在 rootReducer 下添加了 initialState :(
  • 你仍然遇到同样的错误TypeError: Object(...) is not a function?
  • 是的,先生!不幸的是:/
  • 我怀疑,composeEnhancer 中的一个函数返回 undefined.. 你能否 console.log reactReduxFirebase(firebase, rrfConfig)reduxFirestore(firebase) 并确保它们返回函数类型
  • 我在); 下的底部添加了console.log(reactReduxFirebase(firebase, rrfConfig)) console.log(reduxFirestore(firebase)) 但是,控制台没有记录任何内容。我的格式不正确吗?
猜你喜欢
  • 1970-01-01
  • 2018-11-16
  • 2019-04-05
  • 2019-01-30
  • 2020-08-03
  • 1970-01-01
  • 2018-12-24
  • 2021-10-26
  • 2019-01-25
相关资源
最近更新 更多