-
Notifications
You must be signed in to change notification settings - Fork 1
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
usePromise #24
Comments
I'd honestly like to convert https://github.com/jxom/react-loads to use hooks - this kind of abstraction will be real useful! |
This is cool, and an idea that I was thinking about while reading the hooks documentation. What I'm really curious to understand better is best practices regarding when to use Suspense versus when to use hooks. It seems like this API here is doing some of the same things that the Suspense API is being designed to do. I'm pretty curious about this topic, so I tweeted about it. I know that the React team is super busy – especially right now after dropping this huge RFC – but maybe we'll hear back from them. |
Yeah, I've been actively thinking about it too @jamesplease. I'd love to understand more about this as well! |
Dropped in favor of Suspense. https://twitter.com/sophiebits/status/1055702535183290369 Thanks @jamesplease. |
Hmm, I think this could still be a valid approach though, as you can actually “suspend” from within a hook. I think it would still be pretty useful to create an abstraction around promise state/data with a hook. Correct me if I’m wrong in my thinking though! |
Is that so? I thought Suspense (and suspending) meant turning render into something like a coroutine, whereas custom hooks acted more like an Observable, “pushing” values into the Component that cause it to rerender. Can custom hooks be used to transform render into a coroutine as well? If you just mean that custom hooks can be long-living (like an “epic”), then I don’t think I would use the word “suspending” to describe that based on my current understanding. I could be wrong on my word usage tho’
I think this depends on the exact nature of subtle nuances that Sophie mentioned in her reply to me. She mentions “concurrent renders,” which sounds like it may just be an optimization thing, but I’m not sure. I plan to do some more thorough testing of the Suspense component vs custom hooks over the next few days to see what the differences are, and how they might interact with other things in React (like Context updates). |
Well I thought the same as you until I was scrolling twitter and saw Dans tweet...
I think it might be best to wait until Suspense is fully documented before we make some kind of assumption about this though? Let me know how you go in your investigations though - am curious! |
That’s pretty interesting. I hadn’t considered that, but it makes sense. Waiting for docs on the Suspense component is definitely the right thing to do, but we’re already playing around with an unstable API (hooks), so I think it is fine to explore different things, even if we find out later that it isn’t encouraged by the React team. If we assume (for kicks) that the Suspense component is stable, and that the basics of the hooks API will remain the same, do you think it would make sense to allow for a hook like this to optionally suspend? The Apollo Client’s Query component has a prop to toggle this behavior iirc. |
Hey friends, after searching the issues for Feel free to take a look ... I'm curious what everyones thoughts are: The hook I wrote should be ready to be merged as is, but I'm happy to make tweaks according to feedback |
Agree with @jamesplease, learning about Suspense will help a lot with the React-standard way to do this @hanford not sure we should merge #44 as we can leave this issue open in case anyone else has an opinion/idea about promises + React Hooks |
The text was updated successfully, but these errors were encountered: