Skip to content

useSWR + service layer? #639

Closed Answered by sergiodxa
mateus4k asked this question in General
Discussion options

You must be logged in to vote

I do this, but you should pass params as part of the key (note the key can be anything except an object) not only a string with a URL

useSWR(["data", id, orderBy, order], (key, id, orderBy, order) => getData(id, { orderBy, order }), { initialData })

Also note if you use null as key SWR will not call your fetcher function.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mateus4k
Comment options

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