use-async-cache
v0.0.1
Published
![Version](https://img.shields.io/npm/v/use-async-cache?style=for-the-badge) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](#) [![Twitter: jiangweixian](https://img.shields.io/twitter/follow/jiangweixian.svg?sty
Downloads
10
Readme
use-async-cache
a simple react hooks implement for async cache store;
a list of
[element1, ..., elementn]
useasync-date from same api
。[element1, ..., elementn]
will share same async-cache,api
will request once。
see more props
Install
npm install
Usage
api will only request once
import React from 'react';
import { useAsyncCache } from 'use-async-cache';
import { cache } from '@/api/cache';
export const Element = () => {
const { cached } = useAsyncCache({
id: '1',
api: cache.fetch,
});
return <span>{cached && cached.data}</span>;
};
import React from 'react';
import { Element } from './components/Element';
export default () => {
return Array(10)
.fill(0)
.map(() => <Element />);
};
api.cache.fetch will only request once for 10 element
Author
👤 JW
- Twitter: @jiangweixian
- Github: @JiangWeixian
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator