Socket
Book a DemoInstallSign in
Socket

@yieldstudio/react-query-factory

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yieldstudio/react-query-factory

Yield Studio React Query Factory

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
0
Created
Source

@yieldstudio/react-query-factory

Our typesafe factories for React Query protected by Zod

Latest Version Total Downloads

Getting Started

Installation

You can install React Query via NPM

yarn add --dev @yieldstudio/react-query-factory

APIs

APIDescription
createQueryCreate a QueryFunction used to create a React Query hook
createMutationCreate a MutationFunction used to create a React Query hook
setAxiosInstanceUse to provide a custom axios instance that will be used by factories
getAxiosInstanceGet the axios instance used by the factories
TypedFormDataPolyfill for FormData Generic

Quick Start

Create a client and provide him to your App

import {
  QueryClient,
  QueryClientProvider,
  setAxiosInstance,
} from '@yieldstudio/react-query-factory';
import { axios } from "@utils/axios";

const queryClient = new QueryClient();

function App() {
  setAxiosInstance(axios); // optional

  return (
    <QueryClientProvider client={queryClient}>
      {/* my app */}
    </QueryClientProvider>
  );
}

createQuery

Create a React Query hook with our createQuery factory

import { useQuery, createQuery } from '@yieldstudio/react-query-factory';
import { array, object, string } from 'zod';
import { QUERY_CACHE_KEY } from '@constants/QueryCacheKey';

const schema = object({
  data: array({
    id: string(),
    label: string(),
  }),
});

export const queryFn = createQuery(schema);

export function useTodosQuery() {
  const queryKey = QUERY_CACHE_KEY.todos.list());
  return useQuery({ queryKey, queryFn });
}
Usage
const { data, isLoading, ... } = useTodosQuery();
// data -> { data: Array<{ id: string; label: string }> }

createMutation

Create a React Query mutation hook with our createMutation factory

import { useMutation, createMutation } from '@yieldstudio/react-query-factory';
import { object, string } from 'zod';

const schema = object({
  id: string(),
  label: string(),
});

type OrderInput = {
  label: string;
};

const mutationFn = createMutation<OrderInput, typeof schema>('POST', '/v1/todos', schema);

export function useCreateTodoMutation() {
  return useMutation(mutationFn);
}

Usage
const { mutateAsync } = useCreateTodoMutation();
const data = await mutateAsync({ label: 'my todo label' });
// data -> { id: string, label: string }

Credits

Powered by Yield Studio team members

License

The MIT License (MIT). Please see License File for more information.

Keywords

typesafe

FAQs

Package last updated on 24 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.