How to filter already fetched data and trigger re-rendering? #2814
Unanswered
dusanbrankov
asked this question in
Q&A
Replies: 1 comment 2 replies
-
You can mutate data without revalidation with the https://swr.vercel.app/docs/mutation#parameters const { data, mutate } = useSWR(key, fetcher);
const handleCategoryChange = (e) => {
const selectedCategory = e.target.value;
const filteredProducts = fetchedProducts.filter(product =>
product.category === selectedCategory);
mutate(filteredProducts, { revalidate: false });
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I''ve just started using SWR and I have a very basic question.
I want to filter data that has already been fetched. As far as I understand, I can do that with
mutate()
, but it requires an additional API request. But is it possible to extract some data using the native JSfilter()
method to update the UI without having to make an additional API request?Here's an example of what I'm trying to accomplish:
Sorry if this is a dump question, I'm still trying to figure out how to use SWR properly.
I would really appreciate any help. Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions