Skip to content

Allow generation of simple query functions instead of hooks #123

Closed
@bryanjtc

Description

@bryanjtc

Is your feature request related to a problem? Please describe.
I cannot use a hook outside a component. This is not ideal when I use react router loaders.

Describe the solution you'd like

// Current query definition
export const useContactDetailsServiceGetContactDetails = ({ client }, queryKey?, options?) => 
  useQuery({ 
    queryKey: Common.UseContactDetailsServiceGetContactDetailsKeyFn({ client }, queryKey), 
    queryFn: () => ContactDetailsService.getContactDetails({ client }), ...options 
  });

// New query definition Option
export const UseContactDetailsSimpleServiceGetContactDetails = async (queryClient, { client }, queryKey?, options?) => 
  await queryClient.ensureQueryData({
    queryKey: Common.UseContactDetailsServiceGetContactDetailsKeyFn({ client }, queryKey),
    queryFn: () => ContactDetailsService.getContactDetails({ client }),
  })

// This will allow me to do this
export const loader =
  (queryClient) =>
  async ({ params }) => {
    return await UseContactDetailsSimpleServiceGetContactDetails(queryClient, { params.client })
  }

Adding a cli option to generate one type of query or both can be added.

Describe alternatives you've considered
Manually creating the new query definition

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions