| 1 |
import { useSWRConfig } from 'swr' |
| 2 |
|
| 3 |
export const useCache = () => { |
| 4 |
const { cache } = useSWRConfig() |
| 5 |
return (keyToMatch) => cache.get(findKey(keyToMatch, cache)) |
| 6 |
} |
| 7 |
const findKey = (partial, map) => { |
| 8 |
for (const key of map.keys()) { |
| 9 |
if (key.match(partial)) return key |
| 10 |
} |
| 11 |
} |
| 12 |
|