反应质量突变剂量刷新

发布于 2025-01-24 16:29:59 字数 921 浏览 1 评论 0原文

我还有另一个“另一个组件中的特定清单”的获取,但是当帖子对其进行辩护时,它只会在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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小糖芽 2025-01-31 16:29:59

原因是什么?

很难说,而无需看到整个代码 /代码和框复制。有些要关注的事情是:

  • 匹配查询键(上情况 /下情况)
  • 确保queryclient < / code>稳定:在您的应用程序组件外创建,或在状态或参考实例上进行内部。 。否则,重新渲染将创建一个新客户端,将缓存丢弃。
  • 也许您的突变未成功,因此未调用OnSuccess

What could the reason be?

hard to tell without seeing the whole code / a codesandbox reproduction. Some things to keep an eye on are:

  • matching query keys (upper case / lower case)
  • make sure the 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.
  • maybe your mutation is not Successful, so onSuccess is not called.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文