Skip to content

question abount key serialization #598

Answered by pke
anc95 asked this question in General
Discussion options

You must be logged in to vote

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:

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anc95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants