react-use-effect-async
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-use-effect-async

npm version

Async useEffect hook. Just because I was lazy to create this hook on every project.

Install

$ npm install react-use-effect-async

Usage

import React from 'react';
import useEffectAsync from 'react-use-effect-async';

export function Demo() {
  const [data, setData] = React.useState(null);

  useEffectAsync(async () => {
    const response = await fetch('https://api.github.com/users/abranhe');
    const data = await response.json();

    setData(data);
  }, [data]);

  return <div>{!data ? <p>Loading...</p> : <p>{data.name}</p>}</div>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-use-effect-async

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

3.32 kB

Total Files

6

Last publish

Collaborators

  • abranhe