将Firebase作为参数添加到thunk时,Object(...)不是函数 [英] Object(...) is not a function when adding firebase as argument to a thunk
问题描述
使用redux配置Firebase对我来说是一个痛苦.
It's being a pain to me to configure firebase with redux.
我不知道出了什么问题,但我感到很困惑.我正在尝试将 getFirebase
和 getFirestore
作为参数传递给 thunk
,但出现此错误:
I don't know what's wrong but I feel so stuck. I'm trying to pass getFirebase
and getFirestore
as arguments to the thunk
but I'm having this error:
在尝试将其他参数添加到thunk之前,我已经开始工作了.我正在使用以下代码:
I got it working before trying to add the extra argument to the thunk. I'm using the code below:
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'
import rootReducer from './modules'
import {reduxFirestore, getFirestore} from 'redux-firestore'
import {reactReduxFirebase, getFirebase} from 'react-redux-firebase'
import fbConfig from './firebase/config'
export function initializeStore(initialState) {
const _thunk = thunk.withExtraArgument({ getFirebase, getFirestore })
const middlewareEnhancer = applyMiddleware(_thunk)
const composedEnhancers = compose(
middlewareEnhancer,
reduxFirestore(fbConfig),
reactReduxFirebase(fbConfig)
)
const store = createStore(rootReducer, initialState, composedEnhancers)
return store
}
您对可能发生的事情有任何想法吗?我很绝望.
Do you have any idea of what could be happening? I'm desperate.
非常感谢您.
推荐答案
如果您提到'redux-firestore'和'react-redux-firebase'的版本,那就太好了.
It would be great if you mention the version of 'redux-firestore' and 'react-redux-firebase'.
react-redux v6最近进行了迁移: http://react-redux-firebase.com/docs/v3-migration-guide.html
There is a recent migration for react-redux v6: http://react-redux-firebase.com/docs/v3-migration-guide.html
您可能需要在代码中进行的更改:
The changes you might need to do in your code:
- import { reactReduxFirebase, getFirebase } from 'react-redux-firebase'
+ import { ReactReduxFirebaseProvider, getFirebase } from 'react-redux-firebase'
- import { reduxFirestore, getFirestore } from 'redux-firestore'
+ import { createFirestoreInstance, reduxFirestore, getFirestore } from 'redux-firestore'
+ import firebase from "firebase/app";
当您具有react-redux-firebase的最新版本时,将使用此方法,因为reactReduxFirebase的API已删除.还要如下更改composedEnhancers:
This is used when you have recent version for react-redux-firebase as the API for reactReduxFirebase is removed. Also change the composedEnhancers as below:
- const composedEnhancers = compose(
- middlewareEnhancer,
- reduxFirestore(fbConfig),
- reactReduxFirebase(fbConfig)
- )
+ const composedEnhancers = compose(
+ middlewareEnhancer,
+ reduxFirestore(firebase, fbConfig)
+ )
添加react-redux-firebase道具
Add the react-redux-firebase props
+ const rrfProps = {
+ firebase,
+ config: fbConfig,
+ dispatch: store.dispatch,
+ createFirestoreInstance,
+ }
您需要为您的应用提供react-redux-firebase道具:
And you need to provide react-redux-firebase props to your app:
<ReactReduxFirebaseProvider {...rrfProps}>
<App />
</ReactReduxFirebaseProvider>
它应该可以正常工作.您可以按照上面的链接中所述添加rrfConfig,以防万一它仍然不起作用.
It should work fine. You can add rrfConfig as mentioned in the link given above, in case if it still doesn't works.
这篇关于将Firebase作为参数添加到thunk时,Object(...)不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!