anish000kumar / redux-box

Modular and easy-to-grasp redux based state management, with least boilerplate
MIT License
708 stars 22 forks source link

Store isn't passed to children with newer redux & react-redux versions #32

Closed Ch4t4r closed 4 years ago

Ch4t4r commented 5 years ago

When using the newest versions of react-redux (^6.0.0) and redux (^4.0.1) instead of the versions this project uses (5.0.6 and ^3.7.2) the following exception occurs: Either wrap the root component in a <Provider>, or explicitly pass “store” as a prop to "Connect(MyComponent) when using this setup (simplified):

import React from 'react';
import store from './store'
import { Provider } from 'react-redux';
import MyComponent from './MyComponent';

export default const App = () => (<Provider store={store}><MyComponent></Provider>);
import React, { Component } from "react";
import { module as testModule } from "./store/testModule";
import { connectStore } from "redux-box";
class MyComponent extends React.Component {
  render() {
    return (<div>Hey</div>)
   }
}
export default connectStore({
    test: testModule
})(MyComponent) 


I guess there has been a breaking change between the versions - it does work when using the lower versions in the project. Would be nice if someone more skilled than I am could take a look (and maybe update the dependencies?)

Ch4t4r commented 5 years ago

Seems to be this:

Passing store as a prop to a connected component is no longer supported. Instead, you may pass a custom context={MyContext} prop to both and . You may also pass {context : MyContext} as an option to connect.

From https://github.com/reduxjs/react-redux/releases (6.0.0)

A workaround is to use

"dependencies": {
    "connected-react-router": "^5.0.1",
    "react-redux": "5.0.6",
    "redux": "^3.7.2",
    "redux-box": "^1.6.1"
  }

(Im using connected-router as well)

Ch4t4r commented 5 years ago

After further reading I believe that I have to pass a custom Context into the <Provider>, but that throws another exception as well. This change in v6 of react-redux is really frustrating imo.
I'm not to sure whether redux-box has to change anything at all, close this if necessary.

anish000kumar commented 5 years ago

@Ch4t4r Have hardcoded react-redux version for now, until breaking changes are incorporated into redux-box. Can you check back at your end for redux-box@1.6.2?