Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-async-hook

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-async-hook - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

15

package.json
{
"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",

40

README.md
# 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc