@erexstudio/rext
v1.0.6
Published
A very lightweight and easy to use state managment library for javascript projects.
Downloads
6
Maintainers
Readme
RextStore - Lightweight Caching Solution (> 5 kb)
RextStore is a lightweight and easy-to-use caching library designed to simplify API response caching in your JavaScript or React applications built by Erex Studio. It enables you to cache API responses and retrieve the data anywhere in your app using an identifier, avoiding redundant network calls.
Features
- Cache API Responses: Save API responses and access them without having to make the same network request again.
- Retrieve Data Easily: Fetch the cached data by its identifier from anywhere in your application.
- Lightweight and Simple: Minimal footprint and extremely easy to implement in your project.
Installation
To install RextStore, simply run:
npm i @erexstudio/rext
Usage
Basic Setup
// Import RextStore
import RextStore from "@erexstudio/rext";
// Store API response in cache
const fetchCardList = RextStore('OrderList', () => {
return Api.getOrders(network)
})
//Subsequent calls for the same function will not hit the api.
Retrieving Cached Data
Once the data is cached, you can retrieve it from anywhere in your application without making another network request:
// Get cached data by identifier
const myApiData = await RextStore('OrderList')
Example Use Cases
- Cache API responses to reduce redundant calls.
- Access cached data anywhere in the application with a unique identifier.
- Minimize network requests, saving bandwidth and improving performance.
API
`RextStore(_key, callback)`
_key (string): A unique identifier to store and retrieve data.
callback (function): A function that returns a promise (e.g., an API call). If the key is not found in the cache, this callback is executed, and its result is cached.
Returns: A `Promise` that resolves with the cached or fetched data.
Error Handling
If the provided `callback` function is not defined or there's an error, the promise is rejected with an error message.
License
This project is licensed under the MIT License.