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

fetchState not working if component uses contextTypes #27

Open
Eschon opened this issue Sep 11, 2017 · 1 comment
Open

fetchState not working if component uses contextTypes #27

Eschon opened this issue Sep 11, 2017 · 1 comment
Labels

Comments

@Eschon
Copy link

Eschon commented Sep 11, 2017

I tried using react-router-server in a project that uses react-intl. In some components I need to use the intl context that is provided by react-intl but if I declare contextTypes for that component fetchState doesn't work.

I added console.log statements to the callback of my data fetch method and the callback of renderToString and it seems like the component just ignores that it should fetch data and renders immediately.

@Eschon
Copy link
Author

Eschon commented Sep 12, 2017

Ok I've now tried a few things and I found a few strange behaviours and a workaround for my problem.

The problem with fetchState not working is fixed by adding reactRouterServerAsyncRenderer to the contextTypes. But after I did that this.context.intl which comes from react-intl and was declared in my contextTypes was undefined.

I'm not sure how/why that happens as I don't completely understand the context api. But eventually I found a solution for this. I moved all of the markup (and with that the use of the intl context) that was happening in my component down to a child component. With that I could remove all contextTypes on the component that fetches the data and the intl context works normally on the child component.

I'm not sure if this behaviour can be improved in react-router-server but I think it should be at least mentioned somewhere in the documentation.

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

No branches or pull requests

2 participants