lib-react-hooksGeneral purpose React hooks library ⚛️

联合创作 · 2023-09-22 21:06

React Hooks Library



General purpose React hooks library





npm version build status coverage status


Installation


Install with yarn:



$ yarn add lib-react-hooks


Or, npm if you prefer:



$ npm install --save lib-react-hooks


Usage


Simply import any hooks you want to use in your React component. Example using useAsync:



import React from 'react';
import { useAsync } from 'lib-react-hooks';

const Component = () => {
const request = useAsync(async () => {
const response = await fetch('https://api.example.com/users/123');
return response.json();
});

return (
<div>
{request.complete ? (
<p>{`Name: ${request.data.name}`}</p>
) : (
<p>Loading...</p>
)}
</div>
);
};


Available hooks


See the documentation site for more.


License


MIT License. See LICENSE file for details.

浏览 18
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报