currently i am using SWR to data fetching, i trying to use Mutation feature of SWR to refetch the new data but this occurred a problem when i am calling mutate() by key was added new query params.
Here's my code not working:
import useSWR, { useSWRConfig } from 'swr'
function Profile () {
const { mutate } = useSWRConfig()
const { data } = useSWR('/api/post', fetcher)
return (
<div>
<h1>Title post {data.title}.</h1>
<button onClick={() => {
mutate('/api/post?author=1&pricing=1')
}}>
View more information of this post!
</button>
</div>
)
}
I read docs from SWR and i know the key of the mutate should be the same to key in useSWR() but in my case need more query params to get the corresponding data
How can i solve this problem? Helps me please!