Replies: 1 comment 5 replies
-
|
I don't understand the proposal mostly that I don't know what things like createComputed(data)
I've never looked at these libraries but this was roughly what I was thinking. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As we know,
Suspense(originally a React component) is a Component for displaying fallbacks when a certain resource was suspended.createResourceprovided an API to perform data-fetching while coordinating with the nearestSuspenseboundary to display fallback. This is ideal however there are libraries or snippets that provide a completely different strategy for data-fetching. For instance, stale-while-revalidate-based data-fetching libraries (e.g.react-queryor potentially, a Solid port of SWR) tend to show the previous data for a certain amount of time until the new data arrives, otherwise it shows the fallback. This is different fromcreateResourcewhich is anetwork-firststrategy.Currently to circumvent this problem we can wrap the library or the strategy into a
createResourcebut that leads to unnecessary overhead or memory leak.React provided a simple way of suspending components which is for
Suspenseto catch a thrown promise. The feature is flexible enough to be called across certain contexts, but isn't direct enough to skip error boundaries (which is whatcreateResourceexcels at).A proposal for this API is to provide a function (let's call it
suspend).suspendreceives an accessor that returns a Promise result (Extra: please see #608), in which it keeps track for the entireSuspenselifecycle.Suspensewill keep all of the results (or just track them from their respective components) and reacts to the state of the results to display the fallback indefinitely. Here's how it would look likeSince Solid's
Suspenseis optional forcreateResource, callingsuspendis optional too.suspendis also useful for the third-party libraries or snippets as a means to communicate withSuspenseboundaries. It is also simple and flexible enough for users to write their own resources. This potentially allows creation of global resources (which Solid lacks currently) which allows components to share the same instance of resource.Beta Was this translation helpful? Give feedback.
All reactions