0.1.1 • Published 8 months ago

react-fetch-tools v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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 as POST PUT or DELETE

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 method GET
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.

0.1.1

8 months ago

0.1.0

8 months ago