-
I wonder if composite keys are actually recommended or should mutation happen via useEffect? const { data } = useSwr(["user", sessionId])
// vs
const { mutate } = useSwr("user")
useEffect(() => mutate(), [mutate, sessionId]) The issues with the first variant are:
The second variant has none of the above mentioned drawbacks, but its more boilerplace code What is recommended by the team at vercel? @shuding |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yeah this is a great question! For this specific use case, we use the second variant because "user" is a global singleton. And we also have an effect to revalidate when:
Seems like a special case though, but good to have a section or example in the documentation. I'll note this down! |
Beta Was this translation helpful? Give feedback.
Yeah this is a great question! For this specific use case, we use the second variant because "user" is a global singleton. And we also have an effect to revalidate when:
Seems like a special case though, but good to have a section or example in the documentation. I'll note this down!