Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Could not find "store" in the context of "Connect(ConnectedRouterWithContext)" #244

Closed
UbikZ opened this issue Jan 22, 2019 · 2 comments

Comments

@UbikZ
Copy link

UbikZ commented Jan 22, 2019

Context

  • I need to deliver a UMD library which export one global component.
  • This component will initialize all the stuff I need (store, i18n, routes, etc.)

Error

Uncaught Error: Could not find "store" in the context of "Connect(ConnectedRouterWithContext)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(ConnectedRouterWithContext) in connect options.

For the record

  • I've tried to pass custom context (with store state) inside the <ConnectedRouter> component in order to fix the issue, but got other errors.

The connected-react-router lib works like a charm when used without this atypical system (same code) thus.

Is there something I'm missing ?

Thank's for the answers.

Gabriel.

EDIT : not the same issue that #241

@UbikZ
Copy link
Author

UbikZ commented Jan 23, 2019

Seems like ReactRouterRedux context (https://react-redux.js.org/using-react-redux/accessing-store) is failing to be used with the ecosystem I want to use : client JS <-> remote own framework JS <-> remote libraries (react, redux, etc.).

Find a way to handle this properly : need to use custom context in several places.

const StoreContext = React.createContext(null);

render = () => {   
    return (
      <Provider store={store} context={StoreContext}>
        <ConnectedRouter history={history} context={StoreContext}>
          ....
        </ConnectedRouter>
      </Provider>
    );
  };

And connect component (react-redux) with context :
connect(mapStateToProps, mapDispatchToProps, null, {context: StoreContext});

Fix my issue.
I don't know if there is some better solution for that.

@UbikZ UbikZ closed this as completed Jan 23, 2019
@clayrisser
Copy link

I'm having the same problem. I don't want to have to provide the storeContext every time I connect redux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants