Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 539 Bytes

useAsyncEffect.md

File metadata and controls

28 lines (23 loc) · 539 Bytes

useAsyncEffect

Usage

import { useAsyncEffect } from "default-hooks";

const Demo = () => {
  const [result, setResult] = React.useState<ItemType[]>([]);
  useAsyncEffect(async () => {
    const list = await axios.get<ItemType[]>(
      "https://picsum.photos/v2/list?page=2&limit=50"
    );

    setResult(list.data);
  }, []);

  return (
    <div>
      {result.map(item => (
        <span key={item.id} style={{ display: "inline-block" }}>
          hi I'm {item.author}
        </span>
      ))}
    </div>
  );
};