
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@yieldstudio/react-query-factory
Advanced tools
Our typesafe factories for React Query protected by Zod
You can install React Query via NPM
yarn add --dev @yieldstudio/react-query-factory
API | Description |
---|---|
createQuery | Create a QueryFunction used to create a React Query hook |
createMutation | Create a MutationFunction used to create a React Query hook |
setAxiosInstance | Use to provide a custom axios instance that will be used by factories |
getAxiosInstance | Get the axios instance used by the factories |
TypedFormData | Polyfill for FormData Generic |
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>
);
}
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 });
}
const { data, isLoading, ... } = useTodosQuery();
// data -> { data: Array<{ id: string; label: string }> }
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);
}
const { mutateAsync } = useCreateTodoMutation();
const data = await mutateAsync({ label: 'my todo label' });
// data -> { id: string, label: string }
Powered by Yield Studio team members
The MIT License (MIT). Please see License File for more information.
FAQs
Yield Studio React Query Factory
We found that @yieldstudio/react-query-factory demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.