API does not fetch data when client uses parameters from useParams in NextJS
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",
}
even after i changed the static parameters it still doesn't appear
should appear /workspaces/1212121212121212121
Hey, thanks for reporting, we will take a look on this issue 👀
Hey, we released the 7.0.0 which was tested really extensivelly, in case of any further issues, let us know 👍🏻