-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
Side note: I am writing this with my jaw on the floor. What a clean API. Nice work guys. 😍
This issue refers to the idea of waterfalls as mentioned in the react docs.
https://reactjs.org/docs/concurrent-mode-suspense.html#for-library-authors
From a glance, it appears that the suspense based API does not take the above optimization into consideration. If I am not mistaken, to avoid waterfalls, we need to declare the API calls first(which will init the fetch calls), and then read the data from another call (read method in relay), which will throw the promise.
Is this already done in the library? If not, do you guys plan to do it in the future? How would the API look like?
PS: In my head, the API should look something like below
function MyComponent(props) {
// First we declare the list of fetch calls. Here we use an object. Could be an array instead.
// Doing this will NOT trigger suspense. i.e. A promise shall not be thrown.
// But the API calls will be triggered in parallel
const fetcher = useSuspenseSwr({
key1: {/*fetch config for key 1*/},
key2: {/*fetch config for key 2*/},
});
// and then call fetcher.fetch('key1') somewhere in the code
// This is when the promise will be thrown
}TheMcMurder, samcx, bbenezech, nickbreaton, hardfist and 2 morebbenezech