hyper-fetch icon indicating copy to clipboard operation
hyper-fetch copied to clipboard

API does not fetch data when client uses parameters from useParams in NextJS

Open shiqocred opened this issue 10 months ago • 2 comments

Describe the bug In my nextjs application, I am using useFetch to fetch data from some APIs by requesting parameters from useParams on the client side, but after I tried according to the useFetch documentation, it is not working as expected.

@/src/app/(dashboard)/workspaces/[workspaceId]/client.tsx

"use client";

import { useWorkspaceId } from "@/features/workspaces/hooks/use-workspace-id";
import { useFetch } from "@hyper-fetch/react";
import {  getWorkspace } from "@/features/api/workspaces";

export const WorkspaceIdClient = () => {
  const workspaceId = useWorkspaceId();

  const { data: workspace, loading: loadingWorkspace } = useFetch(
    getWorkspace.setParams({ workspaceId }),
    { disabled: !workspaceId }
  );
}

@/features/api/workspaces.ts

import { client } from "@/lib/hyper-fetch";
import { WorkspaceType } from "@/lib/schemas";

export const getWorkspace = client.createRequest<WorkspaceType>()({
  endpoint: `/workspaces/:workspaceId`,
  method: "GET",
});

@/features/workspaces/hooks/use-workspace-id

"use client";

import { useParams } from "next/navigation";

export const useWorkspaceId = () => {
  const params = useParams();
  return params.workspaceId as string;
};

To Reproduce I do as documentation

Expected behavior Once the "disabled" property turns to false, I expect the command to be executed.

{
  "next": "15.1.5",
  "react": "^19.0.0",
  "react-dom": "^19.0.0",
  "typescript": "^5",
  "@hyper-fetch/axios": "^6.0.0",
  "@hyper-fetch/core": "^6.0.0",
  "@hyper-fetch/react": "^6.0.0",
}

shiqocred avatar Feb 09 '25 17:02 shiqocred

even after i changed the static parameters it still doesn't appear

should appear /workspaces/1212121212121212121

Image

shiqocred avatar Feb 10 '25 06:02 shiqocred

Hey, thanks for reporting, we will take a look on this issue 👀

prc5 avatar Feb 14 '25 09:02 prc5

Hey, we released the 7.0.0 which was tested really extensivelly, in case of any further issues, let us know 👍🏻

prc5 avatar Jun 26 '25 11:06 prc5