Gathering detailed insights and metrics for @justinekizhak/use-resource-hook
Gathering detailed insights and metrics for @justinekizhak/use-resource-hook
Gathering detailed insights and metrics for @justinekizhak/use-resource-hook
Gathering detailed insights and metrics for @justinekizhak/use-resource-hook
npm install @justinekizhak/use-resource-hook
Typescript
Module System
Node Version
NPM Version
TypeScript (91.71%)
JavaScript (4.18%)
CSS (2.11%)
HTML (1.91%)
Shell (0.08%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
2,432
Last Day
2
Last Week
11
Last Month
49
Last Year
293
174 Commits
2 Watching
9 Branches
2 Contributors
Latest Version
0.9.0
Package Id
@justinekizhak/use-resource-hook@0.9.0
Unpacked Size
16.98 kB
Size
3.56 kB
File Count
3
NPM Version
6.14.16
Node Version
14.19.1
Cumulative downloads
Total Downloads
Last day
-33.3%
2
Compared to previous day
Last week
83.3%
11
Compared to previous week
Last month
2,350%
49
Compared to previous month
Last year
-51.7%
293
Compared to previous year
1
28
The easiest way to do API calls.
1npm i @justinekizhak/use-resource-hook
Refer some of the examples below on how to use it.
Here we are using just the data
state and the Container
component.
The container component will handle the loading and the error state for us.
1import { useResource } from "@justinekizhak/use-resource-hook"; 2 3function App() { 4 const { data, Container } = useResource( 5 { 6 url: "https://jsonplaceholder.typicode.com/posts/1" 7 }, 8 "fetchPost" 9 ); 10 11 return ( 12 <div> 13 <Container>{JSON.stringify(data)}</Container> 14 </div> 15 ); 16}
Here we are using the isLoading
and errorData
state and handling them explicitly in our component.
1import { useResource } from "@justinekizhak/use-resource-hook"; 2 3function App() { 4 const { data, isLoading, errorData } = useResource( 5 { 6 url: "https://jsonplaceholder.typicode.com/posts/1" 7 }, 8 "fetchPost" 9 ); 10 11 if (isLoading) { 12 return <div>Loading...</div>; 13 } 14 15 if (errorData) { 16 return <div>Error: {error && error.message}</div>; 17 } 18 19 return <div>{JSON.stringify(data)}</div>; 20}
This time we will use the Container and style the loading and the error state by ourselves.
1import { useResource } from "@justinekizhak/use-resource-hook"; 2 3function App() { 4 const { data, Container, refetch } = useResource( 5 { 6 url: "https://jsonplaceholder.typicode.com/posts/1" 7 }, 8 "fetchPost" 9 ); 10 11 const loadingComponent = () => <div>Our custom loader. Loading...</div>; 12 13 const errorComponent = (errorMessage, errorData) => ( 14 <div>Our custom error component. Error: {errorMessage}</div> 15 ); 16 17 const handleClick = () => { 18 refetch(); 19 }; 20 21 return ( 22 <div> 23 <button onClick={handleClick}>Refetch</button> 24 <Container 25 loadingComponent={loadingComponent} 26 errorComponent={errorComponent} 27 > 28 {JSON.stringify(data)} 29 </Container> 30 </div> 31 ); 32}
Tutorial docs are generated using Docusaurus and the API docs are generated using typedoc.
To write API docs, refer: https://typedoc.org/guides/doccomments/
To develop docs run:
This will run both the typedoc and docusaurus at the same time
1npm run docs:dev # yarn docs:dev
To build docs run:
1npm run docs:build # yarn docs:build
No vulnerabilities found.
No security vulnerabilities found.