突变和查询无效后的数据仍然过时
Expo,React天然:突变和查询无效后的数据仍然过时。
情况:我突变在当前屏幕上显示的数据,然后在“ Onsostled”或“ OnSuccess”部分中的查询无效。 问题:当前屏幕上仍然显示了陈旧的数据,除非我远离页面并返回。
const { data, isLoading, isError, refetch } = useQuery(
'getAllCategories',
getAllCategories,
{
onSuccess: (data) => {
setSearchResults(Object.values(data));
},
}
);
const deleteCategoryMutation = useMutation(
(id) => {
deleteCategory({ categoryID: id, saveItems: true });
},
{
onSettled: async () => {
await queryClient.invalidateQueries(['getAllCategories']);
refetch();
},
}
);
Expo, React Native: Data still stale after mutation and query invalidation.
Situation: I mutate data displayed on the current screen and then invalidate queries in the 'onSettled' or the 'onSuccess' section.
Problem: Stale data still displayed on the current screen, unless i navigate away from the page and come back.
const { data, isLoading, isError, refetch } = useQuery(
'getAllCategories',
getAllCategories,
{
onSuccess: (data) => {
setSearchResults(Object.values(data));
},
}
);
const deleteCategoryMutation = useMutation(
(id) => {
deleteCategory({ categoryID: id, saveItems: true });
},
{
onSettled: async () => {
await queryClient.invalidateQueries(['getAllCategories']);
refetch();
},
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论