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

Revert swr config generic #2065

Merged
merged 2 commits into from Jul 8, 2022
Merged

Revert swr config generic #2065

merged 2 commits into from Jul 8, 2022

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Jul 7, 2022

Changes

revert #1938

After new mutate API is landed, we're able to clear the cache or partially set cache with it, like mutate((key) => filter(key), data). We encourage users to use mutate API instead of manipulate cache provider itself directly.

Origin Problem

Previously users are struggling with typing with cache provider, and trying to call cache.clear(), which might result into inconsistence between cache provider and react state in swr. So we introduce the new mutate API to let users manipulate cache easily. The type generics for useSWRConfig<CacheType> is a bit redudant if you really want to forcedly type a returned cache from context. You can just use as type guard like below:

const cache = useSWRConfig().cache as CustomCache

By default the cache type is Cache<any>

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 7, 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 537b5af:

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

@huozhi huozhi force-pushed the revert-swr-config-generic branch from 8ab9ac5 to 08dc1c9 Compare July 7, 2022 23:17
@huozhi huozhi force-pushed the revert-swr-config-generic branch from a2c73be to 537b5af Compare July 8, 2022 10:19
@huozhi huozhi marked this pull request as ready for review July 8, 2022 10:24
@huozhi huozhi requested a review from shuding as a code owner July 8, 2022 10:24
@shuding
Copy link
Member

shuding commented Jul 8, 2022

Sounds good!

@shuding shuding merged commit bd0f5b5 into main Jul 8, 2022
@shuding shuding deleted the revert-swr-config-generic branch July 8, 2022 12:37
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

2 participants