-
when I use swr as follow, it will revalidate every time because of swr's key serialization mechanism function App() {
const {data} = useSWR(['/api/list', {id: '123'}]);
// ...
}
|
Beta Was this translation helpful? Give feedback.
Answered by
pke
Sep 17, 2020
Replies: 1 comment
-
You can also just serialise your key.
You will then get the stringified object as second string argument to your fetch function like this: const {data} = useSWR(
['/api/list', JSON.stringify({id: '123'})],
(path, params) => {
fetch(path, { body: JSON.parse(params) })
}
) You just convert it back to an object. Which is guaranteed to not throw, since you just converted it. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
anc95
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also just serialise your key.
const {data} = useSWR(['/api/list', JSON.stringify({id: '123'})]);
You will then get the stringified object as second string argument to your fetch function like this:
You just convert it back to an object. Which is guaranteed to not throw, since you just converted it.