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

Best practice for use with redux? #78

Closed
alexpricedev opened this issue Apr 5, 2019 · 3 comments
Closed

Best practice for use with redux? #78

alexpricedev opened this issue Apr 5, 2019 · 3 comments

Comments

@alexpricedev
Copy link

Hey! I'm loving navi so far but I'm trying to get the static rendering stuff working with redux.

I'm getting this issue:

Could not find "store" in the context of "Connect(Component)". 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(Component) in connect options.

I have this sorta thing in my index.tsx:

renderer(
  <Router navigation={navigation}>
    <Provider store={store}>
      <App>
        <View />
      ...

I've narrowed my issue down to the fact that the components in ./routes.tsx are not being wrapped up in the <Provider>:

const routes = mount({
  '/': route({
    view: <Index />,
  }),
  '/about': route({
    view: <About />,
  }),
  ...

To clarify, this works in dev, but when running build, I get the above error. Any direction would be great!

Cheers

@alexpricedev
Copy link
Author

Okay so I've just reread the docs and now I see that the main() function is only called in "real browsers". Wrapping each route in a <Provider> allows to build to complete.

@jamesknelson
Copy link
Collaborator

Yeah, you should be able to get this to work by adding Redux's Provider to the exports of your register() call, then wrapping your app with it in a custom static renderer.

It's a little convoluted at the moment, although if we can get SSR Support merged into create-react-app, the situation should vastly improve.

If you managed to get it to work, can I close this issue off?

@alexpricedev
Copy link
Author

Nice work with the SSR PR. Good luck with it :) I'll close the ticket as it is working for now, but if you ever know of a cleaner way to do it, commenting on this thread would be greatly appreciate 👍

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