反应质量突变剂量刷新
我还有另一个“另一个组件中的特定清单”的获取,但是当帖子对其进行辩护时,它只会在rewindowfocus上取回它?原因是什么?
const { mutate,isLoading:isAdding } = useMutation((values)=>handleAddValue(values),
{
onSuccess:()=> queryClient.invalidateQueries("specificList")
},
)
async function handleAddValue(values){
return await ShoppingListAPI.post("/addToShoppingList",{
product:values.newValue,
list:values.listId
})
}
if(isAdding){ return <p>Loading...</p> }
if (isLoading) { return <p>Loading...</p> }
return (
<Box>
{data.products &&
<Autocomplete onChange={(event, newValue) => mutate({newValue,listId})
} options={data.products} getOptionLabel={(option) => option.name} renderInput={(params) => <TextField {...params} label="Products" />}></Autocomplete>
}
</Box>
)
I have another fetch of "SpecificList in another component, but when posts excutes it dosent refetch it only refetches on rewindowfocus? What could the reason be?
const { mutate,isLoading:isAdding } = useMutation((values)=>handleAddValue(values),
{
onSuccess:()=> queryClient.invalidateQueries("specificList")
},
)
async function handleAddValue(values){
return await ShoppingListAPI.post("/addToShoppingList",{
product:values.newValue,
list:values.listId
})
}
if(isAdding){ return <p>Loading...</p> }
if (isLoading) { return <p>Loading...</p> }
return (
<Box>
{data.products &&
<Autocomplete onChange={(event, newValue) => mutate({newValue,listId})
} options={data.products} getOptionLabel={(option) => option.name} renderInput={(params) => <TextField {...params} label="Products" />}></Autocomplete>
}
</Box>
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难说,而无需看到整个代码 /代码和框复制。有些要关注的事情是:
queryclient < / code>稳定:在您的应用程序组件外创建,或在状态或参考实例上进行内部。 。否则,重新渲染将创建一个新客户端,将缓存丢弃。
OnSuccess
。hard to tell without seeing the whole code / a codesandbox reproduction. Some things to keep an eye on are:
queryClient
is stable: either created outside of your App component, or inside it on a state or ref instance. Otherwise, a re-render will create a new client, throwing away the cache.onSuccess
is not called.