Skip to content

refactor: fix all react-hooks/exhaustive-deps warnings in useSWRInfinite #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

koba04
Copy link
Collaborator

@koba04 koba04 commented Jan 15, 2021

This is a PR to follow up #902 and #886, and fixes all react-hooks/exhaustive-deps warnings in useSWRInfinite.
I've disabled the warnings by eslint-disable-next-line comments and removed swr.mutate because it's an immutable reference.

swr/src/use-swr.ts

Lines 348 to 353 in 81824c7

const boundMutate: responseInterface<Data, Error>['mutate'] = useCallback(
(data, shouldRevalidate) => {
return mutate(keyRef.current, data, shouldRevalidate)
},
[]
)

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 153f8ac:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration

@@ -118,6 +118,8 @@ function useSWRInfinite<Data = any, Error = any>(
} else {
didMountRef.current = true
}
// initialSize isn't allowed to change during the lifecycle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SWR doesn't support changing initialSize during the lifecycle, does it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't (it's hard to define what should happen if you change that option), maybe we can have a common util to show warning messages like this and #898?

Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@shuding shuding merged commit 856af09 into vercel:master Jan 16, 2021
@koba04 koba04 deleted the fix-all-exhaustive-deps-warnings-in-swr-infinite branch January 16, 2021 14:48
@koba04
Copy link
Collaborator Author

koba04 commented Jan 16, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants