react-async-hook
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "react-async-hook", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Async hook", | ||
@@ -8,2 +8,15 @@ "author": "Sébastien Lorber", | ||
"repository": "http://github.com/slorber/react-async-hook", | ||
"keywords": [ | ||
"react-async-hook", | ||
"async", | ||
"fetch", | ||
"axios", | ||
"promise", | ||
"react", | ||
"react-native", | ||
"reactjs", | ||
"reactnative", | ||
"hooks", | ||
"hook" | ||
], | ||
"engines": { | ||
@@ -10,0 +23,0 @@ "node": ">=8", |
# react-async-hook | ||
The easiest way to load data in your React components: | ||
- Simplest way to get async result in your React component | ||
- Typescript support | ||
- Refetch on params change | ||
- Handle concurrency issues if params change too fast | ||
- Flexible, works with any async function, not just api calls | ||
@@ -23,23 +27,19 @@ ```jsx | ||
And the typesafe async function: | ||
``` | ||
const fetchStarwarsHero = id => fetch(`https://swapi.co/api/people/${id}/`).then(result => { | ||
if ( result.status !== 200 ) { | ||
throw new Error("bad status = " + result.status); | ||
type StarwarsHero = { | ||
id: string; | ||
name: string; | ||
}; | ||
const fetchStarwarsHero = async (id: string): Promise<StarwarsHero> => { | ||
const result = await fetch(`https://swapi.co/api/people/${id}/`); | ||
if (result.status !== 200) { | ||
throw new Error('bad status = ' + result.status); | ||
} | ||
return result.json(); | ||
}); | ||
return result.json() | ||
}; | ||
``` | ||
# Warning | ||
I'm not sure yet if this library makes any sense. Suspense is probably a better approach that solves the same usecases. | ||
# Why | ||
There already a ton of way to fetch data into components. | ||
This library aims to be the simplest to use and be less verbose than when using alternatives based on hoc/render-props like [react-data-fetching](https://github.com/CharlesMangwa/react-data-fetching) or [react-refetch](https://github.com/heroku/react-refetch). | ||
This library is not meant to be used everywhere, but in many cases, fetching data in an ad-hoc way is a simple solution that is good enough for the usecase. You can keep using Redux/Apollo or other libraries for more advanced usecases. | ||
# Install | ||
@@ -52,2 +52,6 @@ | ||
# Warning | ||
This library does not yet support React Suspense, but hopefully it will as soon as it can. | ||
# License | ||
@@ -54,0 +58,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63
41000