General purpose React hooks library
Install with yarn
:
$ yarn add lib-react-hooks
Or, npm
if you prefer:
$ npm install --save lib-react-hooks
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>
);
};
See the documentation site for more.
MIT License. See LICENSE file for details.