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

type: export MutationFetcher #2184

Merged
merged 1 commit into from
Oct 6, 2022
Merged

Conversation

ssssota
Copy link
Contributor

@ssssota ssssota commented Oct 6, 2022

Hi!

I want to use MutationFetcher type.
The following workaround worked in beta.6 .

import type { MutationFetcher } from 'swr/mutation/dist/mutation/types'

However, now it is no longer available due to #2150 .

Or do you know of any workarounds?

example

type Key = 'ARTICLE_ID'
const likeMutation: MutationFetcher<boolean, {}, Key> = async (key) => {
  const res = await fetch(`/like/${key}`, { method: 'POST' });
  const json = await res.json();
  return json.like;
}

const useLike = (articleId: string) => {
  const res = useSWR(articleId, ...);
  const mut = useSWRMutation(articleId, like);
  ...
}

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 6, 2022

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 66779f0:

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

Copy link
Member

@huozhi huozhi left a comment

Choose a reason for hiding this comment

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

Oh thanks! This is the right way to import it

import type { MutationFetcher } from 'swr/mutation'

The files under dist path is not always guaranteed

@shuding shuding merged commit 7d1b4b8 into vercel:main Oct 6, 2022
@ssssota ssssota deleted the mutation-fetcher-export branch October 6, 2022 12:22
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.

None yet

3 participants