Skip to content

abranhe/react-use-effect-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>;
}

Releases

No releases published

Packages

No packages published