an easy and effortless API calls manager to reduce and optimize your API calls, on the client
Visit E-Query Docs for detailed instructions.
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.
✔️ 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
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.
Use npm or yarn to add e-query to your project.
npm i @mjkhonline/e-query
yarn add @mjkhonline/e-query
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')