vercel / swr-site

The official website for SWR.
https://swr.vercel.app
Apache License 2.0
481 stars 351 forks source link

Use the initCache function for the cache to be passed to the provider in SWRConfig. #550

Open naporin0624 opened 10 months ago

naporin0624 commented 10 months ago

Description

Thank you for developing this wonderful library. I found some changes in the documentation that would make it even better!

swr's defaultCache is created using initCache and swr's global mutate references it. https://github.com/vercel/swr/blob/main/_internal/src/utils/config.ts#L43-L45

There have been a few issues about SWRConfig not working when using global mutate after changing the provider in SWRConfig, and this would solve that problem.

https://github.com/vercel/swr/issues/2799

Example

https://codesandbox.io/s/swr-initcache-ltfwn6?file=/src/App.tsx

vercel[bot] commented 10 months ago

@naporin0624 is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.