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

Export ScopedMutator type #2937

Merged
merged 2 commits into from
May 2, 2024
Merged

Export ScopedMutator type #2937

merged 2 commits into from
May 2, 2024

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Apr 12, 2024

It would be helpful to have access to the ScopedMutator, so that API helper functions can easily specify a useSWRConfig mutate function as a parameter. For example:

import { ScopedMutator, useSWRConfig } from 'swr';

async function myMultiStepApiTask(mutate: ScopedMutator) {
  await postToKey1();
  await mutate(key1);
  await postToKey2();
  await mutate(key2);
}

function MyMultiStepButton() {
  const { mutate } = useSWRConfig();

  return <button type="button" onClick={() => myMultiStepApiTask(mutate)}>Go</button>;
}

Copy link

codesandbox-ci bot commented Apr 12, 2024

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.

@promer94 promer94 merged commit 5c34bfb into vercel:main May 2, 2024
7 checks passed
@joshkel joshkel deleted the scoped-mutator branch May 3, 2024 14:01
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