Skip to content

Support generating useSuspenseQuery hooks when reactHooks is enabled #66

@ckarli

Description

@ckarli

When reactHooks is enabled, the generator currently creates React Query hooks using useQuery. With TanStack Query v5, useSuspenseQuery is increasingly used for Suspense-based data fetching.

It would be useful to support generating useSuspenseQuery hooks.

Proposed config option

Add a configuration option in swagger.config.json, for example:

{
"reactHooks": true,
"useSuspenseQuery": ["getUsers", "getProfile"]
}

or alternatively:

{
"reactHooks": true,
"suspense": true
}

Example generated hook

export const useGetUsers = (params: GetUsersParams) =>
useSuspenseQuery({
queryKey: ["getUsers", params],
queryFn: () => getUsers(params),
});

Why

Aligns with TanStack Query v5 patterns

Enables React Suspense usage without manual hook rewriting

Keeps configuration consistent with existing options like useQuery and useInfiniteQuery

Happy to open a PR if this approach is acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions