0.5.4 • Published 3 years ago

react-fetching-query v0.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Getting started

This library adds a dynamic context of a query. And a transition during request and fetching.

Installation

Run the following

npm install react-fetching-query

Usage

Firstly you need to follow the instructions That's it. You can use react-fetching-library as you normally would. And also you can do the following.

You have a standart action

const getUserInfo: Action<{
	id: number
	name: string
}> = {
	method: "GET",
	endpoint: "/user/info",
}

Then you use QueryProvider to provide a QueryContext to its children

function TopBar() {
	return (
		<QueryProvider action={getUserInfo}>
			<User />
			{/* ... */}
		</QueryProvider>
	)
}

Then you use this context with useQueryContext

function User() {
	const { payload } = useQueryContext()
	return (
		<div>
			<h2>ID: {payload.id}</h2>
			<h2>Name: {payload.name}</h2>
		</div>
	)
}

When using typescript

const { payload } = useQueryContext<typeof getUserInfo>()
// Or with nulish parameter which makes 'getUserInfo' Optional.
const { payload } = useQueryContext<typeof getUserInfo, null>()

Transformation

You can use your own components for handling loading and errors. You will have to add QueryTransform to change the default Transformation.

However you will be able to change it locally

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago