突变和查询无效后的数据仍然过时

发布于 2025-02-08 22:31:06 字数 639 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文