Better Typing support when suspense is enabled
See original GitHub issueSome restrictions can be applied to swr when suspense is enanbled:
key
can’t be falsyfetcher
can’t be nulldata
can’t be undefined
Note: this is tricky as TypeScript can’t handle inherited configs, and those can be dynamic in the runtime.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:14
- Comments:17 (5 by maintainers)
Top Results From Across the Web
Suspense for Data Fetching (Experimental) - React
It lets data fetching libraries deeply integrate with React. If a data fetching library implements Suspense support, using it from React components feels...
Read more >React Suspense in Practice | CSS-Tricks
This post is about understanding how Suspense works, what it does, and seeing how it can integrate into a real web app. We'll...
Read more >10 Minute Read: Understanding React Suspense with Visuals ...
And that's okay! Some data fetching libraries, like Relay, Apollo, and React Query, support Suspense today. The APIs they use are experimental ...
Read more >What Is a Suspense Account? | Examples and How to Use
A suspense account can also hold information about discrepancies as you gather more data. When you open an accounting suspense account, ...
Read more >Improve User Experience in Vue 3 with Suspense
While we can't control internet speeds, we can plan accordingly and prevent users from experiencing a broken application. Luckily, Vue 3 ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe OP and myself are asking for the typing to properly reflect the current implementation, not possible future changes that may or may not come.
In the current implementation it seems to be true that
data
cannot beundefined
with suspense, and that is not correctly reflected in it’s typings, and that ought to be fixed.My suggestion would be to just separate the two. Either a separate hook, or just a separate import like from
swr/suspense
or something like that.That way you could simplify the regular hook by removing all suspense related stuff from there, and the suspense hook could be written with perfect types and no non-suspense related stuff.