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

How to use it with RouterContext ? #1

Closed
Dzale opened this issue Feb 8, 2018 · 1 comment
Closed

How to use it with RouterContext ? #1

Dzale opened this issue Feb 8, 2018 · 1 comment

Comments

@Dzale
Copy link

Dzale commented Feb 8, 2018

Hey there,

below is my server.js file. Any idea how to use this package so i can fetch initial data from API and render it on server side ?

https://gist.github.com/Dzale/b8ae5171b31ac4b65ce96b8b24a05bb4

Best regards,
Nikola

@BernzSed
Copy link
Owner

BernzSed commented Feb 9, 2018

Hi Nikola,

When using this module, you don't fetch your data from your API before the initial render; instead, this module uses a feature of HTTP/2 called "server push" to improve performance.

To use this module, you'll have to use Node's http2 module instead of the http module. Unfortunately, express.js isn't yet compatible with the http2 module, so you'll probably have to use another framework instead (such as Koa or Hapi).

Here is an example that uses koa and http2: https://github.com/BernzSed/axios-push-koa-redux-example/blob/master/src/server.jsx#L28

Finally, you'll have to do something with the axios instance. Consider using a module like react-axios:

markup = renderToString(
  <AxiosProvider instance={axios}>
    <RouterContext {...renderProps}/>
  </AxiosProvider>
);

You could then use the high-order component withAxios in your child components.

Does this help?

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