Skip to content

Commit 9cc6e9e

Browse files
authored
Merge pull request #158 from danybeltran/fix-too-many-re-renders-suspense
fix(suspense):
2 parents a61c35c + 62a5df3 commit 9cc6e9e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-react",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "React hooks for data fetching",
55
"main": "dist/index.js",
66
"scripts": {

src/hooks/use-fetch.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ export function useFetch<FetchDataType = any, BodyType = any>(
829829
const n = {
830830
...p,
831831
data: $$data ?? p.data,
832+
online: p.online,
832833
loading: rpc?.loading ?? false,
833834
error: isDefined($$error) ? $$error : p.error,
834835
completedAttempts: $$completedAttempts ?? p.completedAttempts
@@ -852,6 +853,7 @@ export function useFetch<FetchDataType = any, BodyType = any>(
852853
queue(() => {
853854
canDebounce[resolvedKey] = true
854855
}, debounce)
856+
return $$data
855857
}
856858
}
857859
}
@@ -1172,23 +1174,29 @@ export function useFetch<FetchDataType = any, BodyType = any>(
11721174

11731175
const initializeRevalidation = React.useCallback(
11741176
async function initializeRevalidation() {
1177+
let d = undefined
11751178
if (canRevalidate) {
11761179
if (url !== '') {
1177-
fetchData({
1180+
d = await fetchData({
11781181
query: Object.keys(reqQuery)
11791182
.map(q => [q, reqQuery[q]].join('='))
11801183
.join('&'),
11811184
params: reqParams
11821185
})
11831186
} else {
1187+
d = def
11841188
// It means a url is not passed
11851189
setFetchState(prev => ({
11861190
...prev,
11871191
loading: false,
1188-
error: hasErrors[resolvedDataKey] || hasErrors[resolvedKey]
1192+
error: hasErrors[resolvedDataKey] || hasErrors[resolvedKey],
1193+
completedAttempts: prev.completedAttempts
11891194
}))
11901195
}
1196+
} else {
1197+
d = def
11911198
}
1199+
return d
11921200
},
11931201
[serialize(serialize(optionsConfig)), fetchState]
11941202
)

0 commit comments

Comments
 (0)