Skip to content

Conversation

@huozhi
Copy link
Member

@huozhi huozhi commented May 24, 2022

Closes #1946.

Description

The global mutate API (imported directly from SWR or returned by useSWRConfig) can now accept a filter function, to match multiple keys for mutating:

await mutate(
  key => typeof key === 'string' && key.startsWith('/api/'),
  undefined, // newData | (data => newData)
  false,     // shouldRevalidate = true
)

Breaking Changes

  • This deprecates the use case of accepting a function that returns a key.
  • The Cache interface now requires a keys() method that returns all keys in the cache object, similar to the JavaScript Map instances.

Usage

(See #1946)

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 24, 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 dcda636:

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

@huozhi huozhi marked this pull request as ready for review May 26, 2022 15:45
@huozhi huozhi marked this pull request as draft May 26, 2022 16:31
@shuding shuding marked this pull request as ready for review June 26, 2022 18:02
@huozhi
Copy link
Member Author

huozhi commented Jun 26, 2022

Thank you shu for helping fixing the issues and those changes look good

image

@shuding
Copy link
Member

shuding commented Jun 26, 2022

(I think there’s still one last blocker which is to make useSWRInfinite work properly)

@shuding shuding marked this pull request as draft June 26, 2022 22:04
@shuding shuding marked this pull request as ready for review June 26, 2022 22:05
@shuding
Copy link
Member

shuding commented Jun 26, 2022

OK this is more like a general problem today, need to think deeper about it. Meanwhile this PR can be shipped!

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.

RFC: Mutate multiple items

4 participants