Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af73f5d

Browse files
Ensure useFetch suspends when triggering a service call more than once
useFetch experimental support for React Suspense works great when the call made is only used once. In the event of an application successfully suspending after a service call, and then triggering that same call again, the suspense mechanism does not suspend as expected. This is because the suspenseStatus ref used to keep track of the suspense status is never reset! This change makes it so that when the suspense promise is created, the suspenseStatus ref is reset so that the promise can be successfully thrown for React to catch.
1 parent 6225d32 commit af73f5d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

‎src/useFetch.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function useFetch<TData = any>(...args: UseFetchArgs): UseFetch<TData> {
182182

183183
if (suspense) {
184184
return async (...args) => {
185+
suspenseStatus.current = 'pending'
185186
suspender.current = doFetch(...args).then(
186187
(newData) => {
187188
suspenseStatus.current = 'success'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /