The Wayback Machine - https://web.archive.org/web/20200703195030/https://github.com/vercel/swr/issues/306
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

[question][documentation] Request deduplication #306

Open
andrewmclagan opened this issue Mar 16, 2020 · 3 comments
Open

[question][documentation] Request deduplication #306

andrewmclagan opened this issue Mar 16, 2020 · 3 comments
Labels

Comments

@andrewmclagan
Copy link

@andrewmclagan andrewmclagan commented Mar 16, 2020

Seems request deduplication is a feature as its mentioned in the docs and this PR: #235

If this is the case would you accept a PR to extend the documentation around this feature? As at present its very minimal.

Does request deduplication work as follows? Only one request would be made?

import useSWR from "swr";

function UserProfile() {
  const { data, error } = useSWR("/api/user", fetcher);

  if (error) return <div>failed to load</div>;
  if (!data) return <div>loading...</div>;
  return <p>Name: {data.name}!</p>;
}

function UserAvatar() {
  const { data, error } = useSWR("/api/user", fetcher);

  if (error) return <div>failed to load</div>;
  if (!data) return <div>loading...</div>;
  return <img src ={data.avatarUrl} alt="Profile image" />;
}

export default function App() {
  return (
    <div>
      <UserAvatar />
      <UserProfile />
    </div>
  );
}
@sergiodxa
Copy link
Contributor

@sergiodxa sergiodxa commented Mar 16, 2020

Yes, only one request will be made in that case in that, and once the promise is fulfilled it will update both components.

@andrewmclagan
Copy link
Author

@andrewmclagan andrewmclagan commented Mar 16, 2020

Should I PR to extend the docs? or not worth it?

@shuding
Copy link
Member

@shuding shuding commented Mar 30, 2020

Thank you @andrewmclagan! Yeah it's worth to document it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.