0.1.0-beta.1 • Published 7 months ago

@mjkhonline/e-query v0.1.0-beta.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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-query
yarn add @mjkhonline/e-query

Usage

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

e-query.js.org

License

MIT