1.0.6 • Published 9 months ago

uselongfetch v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

useLongFetch react hook

You can mark asynchronous operation as a long use this hook.

const {
  status: { isLoading, data, error },
  secondsFromStart,
  longFetchHelper,
  isLongFetch,
} = useHelperPromiseFunc(seconds);

useHelperPromiseFunc(seconds: number);

Parameters:

seconds: mark when fetch is long and isLongFetch will true

import { useHelperPromiseFunc } from "uselongfetch";

const SomeYouComponent = () => {
  const {
    status: { isLoading: isLoadingFirst },
    secondsFromStart: secondsFromStartFirst,
    longFetchHelper: fetchHelper1,
    isLongFetch: isLongFetchFirst,
  } = useHelperPromiseFunc(3);

  const {
    status: { isLoading: isLoadingSecond },
    secondsFromStart: secondsFromStartSecond,
    longFetchHelper: fetchHelper2,
    isLongFetch: isLongFetchSecond,
  } = useHelperPromiseFunc(5);

  const someFetch1 = () => fetchHelper1(fetch("http://localhost:3001/"));
  const someFetch2 = () => fetchHelper2(fetch("http://localhost:3001/"));

  return (
    <>
      <button onClick={someFetch1}>Start long fetch 1</button>
      <button onClick={someFetch2}>Start long fetch 2</button>
      <div>Content...</div>
      {isLongFetchFirst && <div>Don't worry. We need more time</div>}
      {isLongFetchSecond && <div>Don't worry. We need more time</div>}
    </>
  );
};
1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago