-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync Data with Firestore - Got Error version
- Loading branch information
1 parent
0b22b0a
commit c38eef4
Showing
5 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import authReducer from './authReducer'; | ||
import postReducer from './postReducer'; | ||
import { combineReducers } from 'redux'; | ||
import { firestoreReducer } from 'redux-firestore'; | ||
|
||
const rootReducer = combineReducers({ | ||
auth: authReducer, | ||
post: postReducer, | ||
firestore: firestoreReducer, | ||
}) | ||
|
||
export default rootReducer; |
c38eef4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error I (and a lot of people were) having is: "Error: Context from react-redux not found. If you are using react-redux v6 a v3.. version of react-redux-firebase is required".
To solve this issue, some people may suggest to fix your react-redux version by downgrading it to less than 6 (i.e.: npm i --save react-redux@^5.1.1 ).
I'm not a big fan of downgrading versions or fixed versions for a large number of reasons; it may be a good temporary workaround, but I woulnd't consider it a solution.
I've researched and found a way to sort this out, basing my answer on this one: https://stackoverflow.com/a/53888416/6217195.
The issue you are getting is clear: "If you have react-redux version v6, you need react-redux-firebase v3". So given all of us (I believe) are using react-redux v6+ we need to migrate react-redux-firebase to v3. When we install normaly react-redux-firebase, npm gives us v2.4.1 (at time of writing), so we have to do an "npm i --save react-redux-firebase@next" to get v3.0.0-beta.2 (at time of writing). Then, we have to migrate your index.js; for this you can follow http://docs.react-redux-firebase.com/history/v3.0.0/docs/v3-migration-guide.html. Basically you have to use ReactReduxFirebaseProvider instead of reactReduxFirebase, createFirestoreInstance instead of reduxFirestore:
import { reduxFirestore, getFirestore } from 'redux-firestore';
// import { reactReduxFirebase, getFirebase } from 'react-redux-firebase';
import { ReactReduxFirebaseProvider } from 'react-redux-firebase'
import { createFirestoreInstance } from 'redux-firestore'
Your store object will look like:
const store = createStore(rootReducer,
compose(
applyMiddleware(thunk.withExtraArgument({ firebaseConfig, getFirestore })),
reduxFirestore(fbConfig),
// reactReduxFirebase(fbConfig),
)
);
Implement rrfConfig and rrfProps objects, and change structure of the element to render
const rrfConfig = { userProfile: 'users' } // react-redux-firebase config
const rrfProps = {
firebase: firebaseConfig,
config: rrfConfig,
dispatch: store.dispatch,
createFirestoreInstance // <- needed if using firestore
}
ReactDOM.render(
<Provider store= { store }>
<ReactReduxFirebaseProvider {...rrfProps}>
,
document.getElementById('root'));
A silly reminder, but when you upgrade versions, remember to restar server.
I found a similar fix has been posted on shaun's github iamshaunjp/React-Redux-Firebase-App#11 (comment), but I thought will be worthy to post it here anyway. Hope it helps!