-
Hi, I have two components. With the first one, I can upload files. In the second one, I list them in a table using paging. In my second component, I am using useSWR this way:
There is nothing special about this I believe, and it works. However, how can I invalidate all the /api/uploads from my first component, so that the second component can refresh itself? I really do not want to have a context between those components, or some kind of parent to both of them to hold the total values and invalidate by looping over all the pages. Ideally, I would do this in the first component, and that would do it: Thanks for your help :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
You can call mutate passing the exact same key, if you want to revalidate them all you can use cache.keys to search the key you want based on a regex and then revalidate them. I have a tiny lib for this use case called swr-mutate-many (https://github.com/sergiodxa/swr-mutate-many). |
Beta Was this translation helpful? Give feedback.
-
SWR v2 has the official way to support this case as Mutate Multiple Items! |
Beta Was this translation helpful? Give feedback.
You can call mutate passing the exact same key, if you want to revalidate them all you can use cache.keys to search the key you want based on a regex and then revalidate them.
I have a tiny lib for this use case called swr-mutate-many (https://github.com/sergiodxa/swr-mutate-many).