Accept glob pattern or RegExp in trigger()
See original GitHub issueThanks a lot for releasing this library! I’m just starting to play around with it but it seems like it’s quite a simplification over what we’re currently doing in our apps to fetch data.
I was wondering about one thing though: After a successful POST request you commonly need to revalidate some related data. If I got it right, you either do that with the revalidate()
function that is returned from useSWR()
or by calling trigger()
with a key. The latter seems like a shortcut in cases where it’d be tedious to pass revalidate()
around between components. However, in cases like these chances are that I also don’t know the exact key (maybe because there’s a bunch of dynamic parameters in there).
What do you think about also accepting something like a glob pattern or a RegExp
as an argument to trigger()
and then revalidating all the matching (and currently visible) queries? That way you could do trigger("/projects*")
or trigger(/\/projects.*/)
instead of the more specific trigger("/projects?page=3&perPage=100")
.
(I haven’t checked out the implementation of SWR so please let me know if I have incorrect assumptions about the internals!)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
I ended up with this by the way:
I like your take @JulianG and this is also my opinion about why I personally don’t want cache APIs to be documented for now. Because ideally they should be covered by some other high level APIs or plugins. It’s dangerous for end users to touch the cache.
(I’d close this PR, it’s kinda unrelated to the topic)