Skip to content
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

fix: Avoid preloading the resource multiple times #2036

Merged
merged 1 commit into from
Jun 18, 2022
Merged

fix: Avoid preloading the resource multiple times #2036

merged 1 commit into from
Jun 18, 2022

Conversation

shuding
Copy link
Member

@shuding shuding commented Jun 18, 2022

In a real-world application, a “preload” action might be initiated from multiple different places and levels (global, inside component, inside hooks, inside event callbacks). Hence deduplication is also needed here.

This improves use cases such as:

<button onHover={() => preload('/api/user?id=' + userId, fetcher)}>

Where you can hover the button multiple times. Also:

function App({ userId }) {
  useEffect(() => {
    preload('/api/user?id=' + userId, fetcher)
  }, [userId])
  ...
}

Where there can be multiple <App/> elements.

@shuding shuding requested a review from huozhi as a code owner June 18, 2022 13:57
@shuding shuding requested a review from koba04 June 18, 2022 13:57
@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 5301224:

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

Copy link
Collaborator

@koba04 koba04 left a comment

Choose a reason for hiding this comment

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

This looks good! Thank you!👍

@koba04 koba04 merged commit 790e044 into main Jun 18, 2022
@koba04 koba04 deleted the shu/08f3 branch June 18, 2022 14:14
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