Using useSWR() without key Doesn't return any data #2808
Answered
by
koba04
mohanas-scg
asked this question in
Q&A
-
export async function getData() {
let res = await fetch("/api/product/", { cache: "no-store" });
if (!res.ok) {
throw new Error("Failed to fetch data");
}
return res.json();
} const {
data: productData,
isLoading,
mutate,
}: SWRResponse<resProductFields[], any, any> = useSWR<resProductFields[]>(getData); Here without key useSWR doesn't return any data can anyone explain this scenario? |
Beta Was this translation helpful? Give feedback.
Answered by
koba04
Oct 2, 2023
Replies: 1 comment 3 replies
-
Yeah, the key param is required, so you need to put a key like |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, that is correct; we use the key internally to store data like cache and some internal state.
You can also pass a non-URL string as the key.