Skip to content

Commit

Permalink
feat: expose mutateTag from package import
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jan 16, 2025
1 parent f0443fc commit 57c789d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/_internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { INFINITE_PREFIX } from './constants'
export { SWRConfig, revalidateEvents, INFINITE_PREFIX }

export { initCache } from './utils/cache'
export { defaultConfig, cache, mutate, compare } from './utils/config'
export {
defaultConfig,
cache,
mutate,
mutateTag,
compare
} from './utils/config'
import { setupDevTools } from './utils/devtools'
export * from './utils/env'
export { SWRGlobalState } from './utils/global-state'
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default useSWR
export { SWRConfig } from './use-swr'
export { unstable_serialize } from './serialize'
export { useSWRConfig } from '../_internal'
export { mutate } from '../_internal'
export { mutate, mutateTag } from '../_internal'
export { preload } from '../_internal'

// Types
Expand Down
23 changes: 20 additions & 3 deletions test/use-swr-mutate-tag.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import { screen, fireEvent } from '@testing-library/react'
import useSWR, { useSWRConfig } from 'swr'
import { createKey, createResponse, renderWithConfig } from './utils'
import { screen, fireEvent, act } from '@testing-library/react'
import useSWR, { useSWRConfig, mutateTag as globalMutateTag } from 'swr'
import {
createKey,
createResponse,
renderWithConfig,
renderWithGlobalCache
} from './utils'
import useSWRInfinite from 'swr/infinite'

describe('mutateTag', () => {
it('should return the global mutateTag by default', async () => {
let localMutateTag
function Page() {
const { mutateTag } = useSWRConfig()
localMutateTag = mutateTag
return null
}

renderWithGlobalCache(<Page />)
expect(localMutateTag).toBe(globalMutateTag)
})

it('should support mutate tag', async () => {
const key1 = createKey()
const key2 = createKey()
Expand Down

0 comments on commit 57c789d

Please sign in to comment.