I an using redux-thunk as a middleware and trying to connect to redux-firestore. When I run the application I am getting the error "TypeError: Object(...) is not a function" at createStore.
import reportWebVitals from './reportWebVitals';
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({getFirestore,getFirebase})),
reduxFirestore(FBConfig),
reactReduxFirebase(FBConfig)
)
);
I am using the extra arguments in my thunk actions like this:
export const createProject=(project)=>{
return(dispatch,getState,{getFirebase,getFirestore})=>{
//asyn call to database
const firestore=getFirestore();
firestore.collection('projects').add({
...project,
authorFirstName:'Nam',
authorLastName:'Pam',
authorId:123,
createAt: new Date()
}).then(()=>{
dispatch({type:'CREATE_PROJECT',project});
}).catch((err)=>{
dispatch({type:'CREATE_PROJECT_ERROR',err})
})
}
};
The error that you are seeing is likely due to upgrading
react-redux-firebasefrom v2 to v3 (or basing new code on outdated examples). This update introduced some breaking changes such as the removal of thereactReduxFirebasestore enhancer function. The package now uses React contexts and introduced some new hooks such asuseFirebaseanduseFirestorewhich allow you to access firebase through the context in function components. But that doesn't help with your thunk.In the page on Redux Thunk Integration, they recommend passing the
getFirebasefunction to thewithExtraArgument.As far as accessing firestore, this GitHub discussion recommends accessing it through the
getFirebasefunction.You want your extra argument to be an object with properties
getFirebaseandgetFirestore. We usegetFirebaseas one property and create an inline arrow function for thegetFirestoreproperty.