prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 559 forks source link

Integration with rematch #904

Open theunreal opened 4 years ago

theunreal commented 4 years ago

Do you want to request a feature or report a bug?

Bug or documentation request, not sure.

(If this is a usage question, please do not post it here—post it on gitter. If this is not a “feature” or a “bug”, or the phrase “How do I...?” applies, then it's probably a usage question.)

What is the current behavior? App fails to load, error: Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar.

Code:

// Create plugins
const persistPlugin = createPersistPlugin({
  version: 2,
  storage: AsyncStorage,
  blacklist: [],
});
const loadingPlugin = createLoadingPlugin({});

const createStoreWithFirebase = compose(
  ReactReduxFirebaseProvider(firebase,
    {
      userProfile: 'users',
      useFirestoreForProfile: true,
      enableLogging: true,
    }),
  reduxFirestore(firebase),
)(createStore);

const configureStore = () => {
  const store = init({
    models,
    redux: {
      createStore: createStoreWithFirebase,
      middlewares: [],
      reducers: {
        firebase: firebaseReducer,
        firestore: firestoreReducer,
      },
    },
    plugins: [persistPlugin, loadingPlugin],
  });

  const persistor = getPersistor();
  const { dispatch } = store;

  return { persistor, store, dispatch };
};

export default configureStore;

What is the expected behavior? Should work

Which versions of dependencies, and which browser and OS are affected by this issue? Did this work in previous versions or setups? "@rematch/core": "^1.4.0", "react-redux-firebase": "^3.3.0", "redux": "^4.0.5", "redux-firestore": "^0.13.0",

prescottprue commented 4 years ago

I don't believe that the way you are using the ReactReduxFirebaseProvider will work as expected. It seems like you are mixing the old API (which used a store enhancer named reactReduxFirebase( with the new API which has the ReactReduxFirebaseProvider (for using context) - please check the use section of the README

theunreal commented 4 years ago

@prescottprue I really can't figure out how to put it both together. No answers at stackoverflow either