[Feature]: Component to resolve multiple promise results from deferred loaders as they come #6149
Replies: 3 comments 4 replies
-
I think somebody else has made a similar proposal. I don't have the link at the moment. Anyway, one of the nice things about Remix is that the core library provides the building blocks you can use to build your solution. For example, |
Beta Was this translation helpful? Give feedback.
-
Stumbled upon this looking for a simpler "wait for all of the promises before rendering the block"... which, if anyone else wanted that, is as simple as: <Await resolve={Promise.all([products, collections])}>
{([products, collections]) => { |
Beta Was this translation helpful? Give feedback.
-
That's very nice @freshollie tyvm 💯 |
Beta Was this translation helpful? Give feedback.
-
Problem
The
<Suspense><Await>...
pattern provides a really nice interface for rendering both the positive and fallback result for a single promise result from a data-loader. However, the pattern does not scale when you wish to use the results from different deferred data results in a single component.#6133Example
Given a loader similar to this
And some component which can display the data as it comes, with some fallback in place when data loading
The only real way to use this component, where the data is shown as it comes, is to make a really messy suspense/await tree 🤢:
In this example, the 3rd order version of this (where there are 3 promises) doesn't scale at all and would be completely unmaintainable.
Solution
I propose here a new component (could be named whatever, but I've gone for
MergeAwaits
) which takes multiple promises and outputs the result of each of them when they resolve.Sourcecode
Usage
Given the same loader and component above, here is the same usage with
MergeAwaits
Questions
MergeAwaits
the source I have provided is what we have used in our project (which doesn't rely on the SSR loses of using state for the promises)Suspense
andAwait
which I am missing which provides the functionality I am looking for?Beta Was this translation helpful? Give feedback.
All reactions