slorber / react-async-hook

React hook to handle any async operation in React components, and prevent race conditions
https://sebastienlorber.com/handling-api-request-race-conditions-in-react
1.19k stars 45 forks source link

Question about exhaustive state check #94

Open 1EDExg0ffyXfTEqdIUAYNZGnCeajIxMWd2vaQeP opened 1 year ago

1EDExg0ffyXfTEqdIUAYNZGnCeajIxMWd2vaQeP commented 1 year ago

In your examples, you use this pattern a lot:

const asyncHero = useAsync(..., ...);
  return (
    <div>
      {asyncHero.loading && ...}
      {asyncHero.error && ...}
      {asyncHero.result && ...}
    </div>
  );

Is this supposed to cover all possibilities? I don't want it to silently fail with an empty div. If so, would it be possible to change the typing to represent this fact?