question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better Typing support when suspense is enabled

See original GitHub issue

Some restrictions can be applied to swr when suspense is enanbled:

  • key can’t be falsy
  • fetcher can’t be null
  • data 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:open
  • Created 2 years ago
  • Reactions:14
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
MoSattlercommented, Jan 8, 2022

It is not, and that the reason why we have #1247 in the first place.

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 be undefined with suspense, and that is not correctly reflected in it’s typings, and that ought to be fixed.

10reactions
Svishcommented, Sep 6, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found