3 ms·
I really puzzled why no one switched to hooks + suspense. I started to use suspense when it was alpha - you don't need any support for this from react itself: j
by ex3ndr 5y ago
I really puzzled why no one switched to hooks + suspense. I started to use suspense when it was alpha - you don't need any support for this from react itself: just catch promise in error boundary and display placeholder.
This makes everything is so easier:
const data = useQuery('/api/user/:id', {id:1});
return (<span>{data.name}</span>);
No error handling, not loaders, just one line.
- spion 5y agoBecause react no longer renders child components in the same stack as the parent after concurrent mode, I think?
- kall 5y agoI started doing this when the third party apollo-react-hooks package came out with support for it years ago. It was wonderful. I have stopped based on hazy recommendations from the react team about what the future looks like, but I miss it. An underrated benefit is that you can depend on data in other hooks in the same component. If you have an error or loading bail-out it makes hooks calls after it conditional.
- merrywhether 5y agoThere’s a Suspense component that does that catch-and-placeholder functionality much more cleanly now. Suspense hasn’t really taken off yet because it’s not quite fully baked, and thus very few libraries are starting to take advantage of it yet. Once we get stale-while-waiting and server-side suspense, things are going to change rapidly.