Check if key exists? #498
-
Is there any way to check if a key exists in the swr cache? I do this little trick sometimes where I preload the next key I am going to fetch with the current data to avoid any change in the UI (fallback to Suspense, etc.) while the data is loading. The drawback of this of course is that I lose the benefit of the cache, which is a pretty major drawback. Ideally, I would check if the next key exists in the cache and, if so, do nothing. But I can't find a way to check the existence of a key. Any help would be much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@raj-altrio hope import {cache} from 'swr'
cache.set(key, value)
cache.has(key) // return true |
Beta Was this translation helpful? Give feedback.
-
How can we do it using swr v2 ? |
Beta Was this translation helpful? Give feedback.
@raj-altrio hope
cache.has(key)
api is the thing you're looking for