0.1.2 • Published 11 months ago

lightweight-use-fetch v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Simple lightweight library for fetching data

The library exposes one hook and one helper method

  1. useFetch
  • accepts two positional params:
  1. key {String} - the key for the data to be cached
  2. useFetchOpts - object with the follow props: endpoint: string; headers?: HeadersInit; method: "GET" | "POST";

    and returns object with:

    • snapshot,
    • isLoading,
    • data,
    • error,
    • fetcher

    The fetcher accepts object with:

    • revalidate?: boolean;
    • optimistic?: boolean;
    • rollbackOnError?: boolean;
    • body?: Record<string, any>;
  3. executeInSequence(type: "sequntial" | "simultaneous" | "race", ...fns: Array<() => Promise):

  • one of the following types - "sequntial" | "simultaneous" | "race"
  • function that return Promises