@mjkhonline/e-query v0.1.0-beta.1
Visit E-Query Docs for detailed instructions.
đĄ What is E-Query?
E-Query is a library for managing API calls in your client application. It's written in TypeScript, and it's fully typed. It's also framework-agnostic, so you can use it with Vue, React, Angular, Svelte, Next, Nuxt, or even vanilla JavaScript.
â What it can do?
âď¸ manage API calls
âď¸ prevent unnecessary fetch
âď¸ optimise & improve performance
âď¸ retry calls on error
âď¸ deactivate call on window hidden
âď¸ refetch on window refocus
âď¸ make different instances
âď¸ customizable
âď¸ get API call status
đ¤ What E-Query is not?
It's not a state management library, it's not a data fetching library, and it's not a caching library. And it has no opinion about how you manage them.
Installation
Use npm or yarn to add e-query to your project.
npm i @mjkhonline/e-queryyarn add @mjkhonline/e-queryUsage
Import eQuery and create an instance of it. Pass in your default options to the constructor. You can find the list of all available options here.
import eQuery from '@mjkhonline/e-query'
const eq = new eQuery({
// pass instance level options
staleTime: 30 * 1000 // 30 seconds
})Then wrap your API calls with useQuery. This invokes your API call's function and returns the promise returned by it.
eq.useQuery('your-query-key',
() => fetch('https://example.com/somedata'),
{ // query level options
staleTime: 60 * 1000, // 1 minute
deactivateOnWindowHidden: true
}
)use getQuery to inquire about the status of your API call.
You can find the list of all available exposed data here.
const { isLoading, isFailed, fetchedAt } = eq.getQuery('your-query-key')Documentation
License
2 years ago
2 years ago