react-fetch-tools
v0.1.1
Published
React hooks for managing http request state
Downloads
1
Readme
fetch-tools
A tiny collection of react hooks to manage your http request state.
Installation
npm
npm install react-fetch-tools
yarn
yarn add react-fetch-tools
bun
bun add react-fetch-tools
How to use?
This package comes with two react hooks (planning to add more).
useMutation
: mutation can be used whenever you are trying to change something on the remote data source, like using http methods such asPOST
PUT
orDELETE
example:
import StarsListCollection from "@/database/schemas/star-list";
import { useMutation } from "react-fetch-tools";
export function useCreateListMutation() {
return useMutation(async function createList({
title,
description,
}: {
title: string;
description?: string;
}) {
await StarsListCollection.create({
title,
description,
reposCount: 0,
});
});
}
useQuery
: This hooks can be used whenever you are trying query remote data source, like using http methodGET
import StarsListCollection from "@/database/schemas/star-list";
import { useQuery } from "react-fetch-tools";
export function useGetStarLists() {
return useQuery(async () => {
const res = await StarsListCollection.findAll();
return res;
});
}
contributions
Contributing
Here's how you can contribute:
- Open an issue if you believe you've encountered a bug.
- Make a pull request to add new features/make quality-of-life improvements/fix bugs.
License
Licensed under the Apache-2.0 license.