我如何比较 useParams() 上一个值和当前值

发布于 2025-01-10 01:32:33 字数 612 浏览 1 评论 0原文

我面临一个问题,我根据 params?.id 获取不同的 api。我需要使用 rtkQuery 比较 api 调用的先前和当前 useParams。但它并没有在 useparams 更改时调用我的 api。

const {
    data: pipelineData,
    isLoading: pipelineDataLoading,
    error: pipelineDataError,
    isSuccess: pipelineDataSuccess,
  } = pipeline.list().usePipelinedetailQuery(
    { params: { id: params.pipelineId }, extendedPath: apiUrls.getPipeline() },
    {
      skip: !params?.pipelineId,
    },
  );

我想使用类似skip: if prev.params.id !== prams.id 的内容。 有两种方法可以做到这一点。 =>通过设置一个状态来存储useParams的上一个值。 =>通过使用rtk查询提供的reffecthh。

还有其他正宗的方法吗?

任何帮助将不胜感激。

I am facing a problem where I am fetching different api's based on params?.id. I need to compare the prev and current useParams for an api call using rtkQuery. But it is not recalling my api on useparams change.

const {
    data: pipelineData,
    isLoading: pipelineDataLoading,
    error: pipelineDataError,
    isSuccess: pipelineDataSuccess,
  } = pipeline.list().usePipelinedetailQuery(
    { params: { id: params.pipelineId }, extendedPath: apiUrls.getPipeline() },
    {
      skip: !params?.pipelineId,
    },
  );

I want to use something like skip: if prev.params.id !== prams.id.
there are two ways to do it.
=>By setting a state to store prev value of useParams.
=>by using refecthh provided by rtk query.

Is there any other authhentic way to do it.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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