Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shiqocred opened this issue Feb 9, 2025 · 2 comments

Comments

@shiqocred
Copy link

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
Copy link
Author

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

should appear /workspaces/1212121212121212121

Image

@prc5
Copy link
Contributor

prc5 commented Feb 14, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants