-
Hello! I'm using SWR + Supabase on NextJS. // /pages/books
async function fetchBooks(_key: string) {
const { data, error } = await supabase
.from<Book>("books")
.select();
if (error) {
throw error.message;
}
return data;
}
...
const { data } = useSWR("books", fetchBooks); This is working well. Now if I want to go to the edit page, I will require the data for that specific book: // /pages/books/edit/[id]
async function fetchBookById(_key: string, id: string) {
const { data, error } = await supabase
.from<Book>("books")
.select()
.eq("id", id);
if (error || data.length !== 1) {
throw error?.message ?? "book not found";
}
return data[0]; //
}
...
const { data } = useSWR("book", fetchBookById); This is also working well, although I have a latency whereas the info should already be available in the cache (because of the My questions are:
Thanks for the help ! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Thanks for providing the example |
Beta Was this translation helpful? Give feedback.
-
I'm trying to reason about this as detailed as I can. Here are some more open questions :)
What happens if there is no cache of The only option is to do the request itself for |
Beta Was this translation helpful? Give feedback.
Thanks for providing the example
@binajmen So far the cache is key based so they're stored under different key. It's not easy to share. But it's a very nice idea that if the cache can be stored in better organized way, and re-use somehow. We'll put it in backlog and brainstorm it