0.1.4-beta • Published 3 years ago
hook-essentials v0.1.4-beta
hook-essentials (Beta)
A Collection of excellent react hooks.
- useAsyncCallback
- useStateObject
- useFormState
- useSelection
- useThrottle
- useToggle
- useGetParams (peer-dependency: react-router-dom)
useAsyncCallback
Example Usage:
import { useAsyncCallback } from 'hook-essentials';
import api from './apiClient';
function App() {
const {
result,
loading,
error,
callback: doAction,
reset
} = useAsyncCallback(api.doAction, {
defaultResult: {
message: 'no results yet'
}
});
if (error) {
return (
<h2>There was an Error.</h2>
);
}
if (loading) {
return (
<h3>loading...</h3>
);
}
return (
<div>
<Button onClick={doAction}>Do Action</Button>
<Button onClick={reset}>reset</Button>
<pre>{JSON.stringify(result, null, 4)}</pre>
</div>
);
}
Signature:
(alias) useAsyncCallback(
callback,
{
defaultResult = undefined,
autoCall = false,
autoCallArgs = [],
} = {}
) : ({
result: mixed
loading: boolean
error: false|Error|mixed
callback: function,
reset: function
})
Coverage
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---|---|---|---|---|---|
All files | 96.45 | 95.35 | 95.59 | 96.77 | |
testUtils.js | 100 | 100 | 100 | 100 | |
useAsyncCallback.js | 100 | 100 | 100 | 100 | |
useFormState.js | 100 | 95.83 | 100 | 100 | 13 |
useGetParams.js | 100 | 100 | 100 | 100 | |
useSelection.js | 100 | 100 | 100 | 100 | |
useStateObject.js | 84.44 | 80 | 81.25 | 85.71 | 9,28-30,42,59 |
useThrottle.js | 100 | 100 | 100 | 100 | |
useToggle.js | 100 | 100 | 100 | 100 |
0.1.4-beta
3 years ago
0.1.3-beta
3 years ago
0.1.2-beta
3 years ago
0.1.1-beta
3 years ago
0.1.0-beta
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago