【发布时间】:2022-07-16 20:59:58
【问题描述】:
目前我正在使用 SWR 来获取数据,我尝试使用 SWR 的 Mutation 功能重新获取新数据,但是当我通过 key 添加了新的查询参数。
这是我的代码不起作用:
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>
)
}
我从 SWR 阅读文档,我知道 mutate 的键应该与 useSWR() 中的键相同,但在我的情况下需要更多查询参数来获取相应的数据
我该如何解决这个问题? 请帮帮我!
【问题讨论】: