Skip to content
Discussion options

You must be logged in to vote

Thanks for the detailed explanation!

The change in 1.0.0 that drops createCache is mostly for concurrent safety.

I think the problem is that you have to access to that mutate function (you still have access to the cache provider) without hooks, which is indeed a bit tricky. Maybe a solution for now is to "expose" the mutate function outside:

const cache = new Map()
let mutate

const Wrapper = ({ children }) => {
  mutate = useSWRConfig().mutate
  return children
}

export { cache, mutate, Wrapper }

And then use Wrapper inside SWRConfig:

<SWRConfig value={{ provider: () => cache }}>
  <Wrapper>
    <App/>
  </Wrapper>
</SWRConfig>

Because the app can be scoped by different cache providers,…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MichaelBurgess
Comment options

Answer selected by MichaelBurgess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants