-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 API for client-side data loading #2638
Comments
@jlongster Ping me on Reactiflux when you get a chance - I have some thoughts but I don't have them in a coherent enough way to formulate a comment here. |
@jlongster I created my own It's an early version but seems to work great for me at the moment. |
Sounds like this might be provided by #2614. |
@jlongster Looks like the proposed |
Conceptually, the way we handle this with the Relay integration is that data are assigned to a particular key. On render, check whether there's anything under the key, and whether an error has occurred. If neither is true, then we know that data is still pending, and we can do whatever is appropriate. This way you don't need to explicitly indicate "loading start"; it's implicit whenever you want data that you don't yet have. There's a broader question here about how data loading should interact with
|
@timdorr @taion Unfortunately I haven't had time to fully look into this. I wish I could give feedback but I'm pretty much willing to do whatever you all tell me to :) If there's a concrete API I can test out I'll try it. Otherwise I'm not sure I'll have time this next week to discuss; I'll be at a Mozilla work week. |
@taion and how to be if it is necessary this received from the server to transform before UI begins is rendered? I for example use Map objects in redux a store. But Map is serialized in an array for transmission to the client. And on his client it is necessary to transform again to Map and just this operation I want to execute prior to rendering of UI and that didn't flicker what messages on that that something is processed. |
@MrEfrem That's a redux issue. It should be handled wherever you're deserializing the data coming from the server, which isn't really related to what we're talking about here. Feel free to hop on Discord or Stack Overflow to get your problem solved. |
@timdorr You faced that as Map is serialized in an array? |
@MrEfrem Yes, that is a redux issue. Just don't use Map and Set in your store. But let's not continue this discussion here, please. This is unrelated to the issue at hand. |
@timdorr I use Map since it provides saving an order of elements as they were added to it, in difference from Object where it is necessary to use some haque. |
@MrEfrem This is issue is about when to load data, not how to load data. Your issue is the latter and doesn't have anything to do with the router. |
@timdorr It was simply the example for what it is necessary for me. But I consider that there shall be an opportunity to delay rendering of a reception to execute any actions to it (including asynchronous). Need of full implementation of this opportunity can appear in hundreds of different other situations and if not now to consider it, somebody again will lift then the same subject. |
Is there anything else to do on this issue? |
And unless the result of this issue is received? Where to look at the best way? |
"Do what AsyncProps does". |
They solve a problem of a fetch of data prior to rendering? |
I think when we release/document the |
👍 |
@jlongster @ryanflorence React Router 2 is really nice + enables some interesting things. I just released a new open source project I've been working on that has handles data fetching & helps structure reducers with react router. |
What about loading synchronous dependencies? I asked this question in discord but couldn't get an answer. Let's say for example I wanna inject an i18n object into my
|
Looks like async-props has been updated, and we have another issue to track docs updates, plus an ongoing rewrite effort. As such, there's nothing more to track on this issue. |
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
I 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 callsetState
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).So what's the best way to:
It'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/filesI'm not really opinionated about this, honestly, I just want something that works. What does everyone think?
EDIT: 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.
The text was updated successfully, but these errors were encountered: