swr icon indicating copy to clipboard operation
swr copied to clipboard

fix: ensure `revalidateOnFocus` and `revalidateOnReconnect` is work

Open u3u opened this issue 3 years ago • 4 comments

When using the same hook in multiple places, setting revalidateOnFocus in one place does not work

In most cases, I want revalidateOnFocus to be turned off by default (this can avoid too many unnecessary requests). So I disabled it in SWRConfig. But under certain conditions, I want to enable it (such as a designated tab). Since this hook may be called in multiple places, if only the first hook is checked, the configuration of other components will be invalid.

u3u avatar Dec 14 '20 06:12 u3u

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 45530d8b47cbf43c057fde4c82c7282db0872085:

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

codesandbox-ci[bot] avatar Dec 14 '20 06:12 codesandbox-ci[bot]

Yes, it’s missing here, it’s been updated

u3u avatar Dec 21 '20 01:12 u3u

@u3u would you mind giving an usage example to explain more about this issue? or it would be nice if supplement more information to the description!

huozhi avatar Dec 22 '20 07:12 huozhi

@huozhi In most cases, I want revalidateOnFocus to be turned off by default (this can avoid too many unnecessary requests). So I disabled it in SWRConfig. But under certain conditions, I want to enable it (such as a designated tab). Since this hook may be called in multiple places, if only the first hook is checked, the configuration of other components will be invalid.

u3u avatar Dec 22 '20 07:12 u3u