Skip to content

Commit

Permalink
refactor: fix all react-hooks/exhaustive-deps warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jan 14, 2021
1 parent 5977d98 commit 21a32c4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/use-swr-infinite.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ describe('useSWRInfinite', () => {
useEffect(() => {
// load next page if the current one is ready
if (size <= 2) setSize(size + 1)
// The setSize function is guaranteed to be referential equal
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [size])

return <div>{data}</div>
Expand Down
2 changes: 2 additions & 0 deletions test/use-swr-int.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ describe('useSWR', () => {
revalidate()
}, 200)
return () => clearTimeout(timeout)
// the revalidate function is always the same reference because the key of the useSWR is static (broadcast-3)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return <>{isValidating ? 'true' : 'false'}</>
}
Expand Down
2 changes: 2 additions & 0 deletions test/use-swr-local-mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ describe('useSWR - local mutation', () => {
return 2
}, false)
}, 1)
// the mutate function is guaranteed to be the same reference
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

renderRecivedValues.push(data) // should be 0 -> 2, never render 1 in between
Expand Down
4 changes: 4 additions & 0 deletions test/use-swr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ describe('useSWR', () => {
revalidate()
}, 200)
return () => clearTimeout(timeout)
// the revalidate function is always the same reference because the key of the useSWR is static (broadcast-3)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return <>{isValidating ? 'true' : 'false'}</>
}
Expand Down Expand Up @@ -1888,6 +1890,8 @@ describe('useSWR - local mutation', () => {
return 2
}, false)
}, 1)
// the mutate function is guaranteed to be the same reference
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

renderRecivedValues.push(data) // should be 0 -> 2, never render 1 in between
Expand Down

0 comments on commit 21a32c4

Please sign in to comment.