1

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.

Wasif Ali
  • 204
  • 1
  • 10
  • Can you call `fetch` inside `useEffect` with `[params.id]` as the second argument in `useEffect`? [`useEffect` docs](https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects) – Jarmo Feb 25 '22 at 17:05
  • At the moment, I am doing same.... But I dont want to use useEffect cause useparams itself is hook. So, I believe it must provide you callback like useState to compare value. – Wasif Ali Feb 25 '22 at 17:41
  • Provided that you are calling `params` and not `useParams()` inside the `useEffect` hook, I do not see a problem with utilizing `useEffect`. – Jarmo Feb 25 '22 at 18:32

0 Answers0