{"action":"created","issue":{"url":"https://api.github.com/repos/rackt/react-router/issues/2638","labels_url":"https://api.github.com/repos/rackt/react-router/issues/2638/labels{/name}","comments_url":"https://api.github.com/repos/rackt/react-router/issues/2638/comments","events_url":"https://api.github.com/repos/rackt/react-router/issues/2638/events","html_url":"https://github.com/rackt/react-router/issues/2638","id":120253948,"number":2638,"title":"Best API for client-side data loading","user":{"login":"jlongster","id":17031,"avatar_url":"https://avatars.githubusercontent.com/u/17031?v=3","gravatar_id":"","url":"https://api.github.com/users/jlongster","html_url":"https://github.com/jlongster","followers_url":"https://api.github.com/users/jlongster/followers","following_url":"https://api.github.com/users/jlongster/following{/other_user}","gists_url":"https://api.github.com/users/jlongster/gists{/gist_id}","starred_url":"https://api.github.com/users/jlongster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlongster/subscriptions","organizations_url":"https://api.github.com/users/jlongster/orgs","repos_url":"https://api.github.com/users/jlongster/repos","events_url":"https://api.github.com/users/jlongster/events{/privacy}","received_events_url":"https://api.github.com/users/jlongster/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-03T19:47:02Z","updated_at":"2015-12-05T16:55:09Z","closed_at":null,"body":"I'm sure this has been talked about a lot, but it doesn't seem resolved. @ryanflorence mentioned filing it: https://twitter.com/ryanflorence/status/672163238482739210\r\n\r\nI thought the `createElement` was a decent API for triggering data fetching, but the problem is that it's fired in the middle of rendering. That means that we can't change any state (shouldn't call `setState` within render); for example redux will update the app state which is fine but connecting components will trigger a render immediately. See https://github.com/jlongster/react-redux-universal-hot-example/pull/2/files These will be triggered because the app state has been updated to reflect that an async request has \"started\" (the \"finished\" events will of course come later and would trigger renders outside of rendering).\r\n\r\nSo what's the best way to:\r\n\r\n1. On the client-side, when a routing component is created and mounted, automatically begin an async request to fetch data\r\n2. Fire multiple data fetching requests in parallel for the list of nested routing components\r\n\r\nIt's easy to do data fetching on the server: we call `match` and get a static list of components and trigger the requests for all of them. There's a PR on react-redux-universal-hot-example to actually do this client-side as well, but I think that's way too much code: https://github.com/jlongster/react-redux-universal-hot-example/pull/4/files\r\n\r\nI'm not really opinionated about this, honestly, I just want something that works. What does everyone think?\r\n\r\nEDIT: Ryan has async-props, https://github.com/rackt/async-props, which looks cool. I can point people to that, but I'd also like to explain a basic strategy for people wanting to roll their own. I get this question a lot with redux-simple-router.\r\n"},"comment":{"url":"https://api.github.com/repos/rackt/react-router/issues/comments/162223102","html_url":"https://github.com/rackt/react-router/issues/2638#issuecomment-162223102","issue_url":"https://api.github.com/repos/rackt/react-router/issues/2638","id":162223102,"user":{"login":"timdorr","id":17882,"avatar_url":"https://avatars.githubusercontent.com/u/17882?v=3","gravatar_id":"","url":"https://api.github.com/users/timdorr","html_url":"https://github.com/timdorr","followers_url":"https://api.github.com/users/timdorr/followers","following_url":"https://api.github.com/users/timdorr/following{/other_user}","gists_url":"https://api.github.com/users/timdorr/gists{/gist_id}","starred_url":"https://api.github.com/users/timdorr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timdorr/subscriptions","organizations_url":"https://api.github.com/users/timdorr/orgs","repos_url":"https://api.github.com/users/timdorr/repos","events_url":"https://api.github.com/users/timdorr/events{/privacy}","received_events_url":"https://api.github.com/users/timdorr/received_events","type":"User","site_admin":false},"created_at":"2015-12-05T16:55:09Z","updated_at":"2015-12-05T16:55:09Z","body":"@jlongster Looks like the proposed `render` API in #2646 should provide this. Feel free to provide feedback if you don't think it will."}}