@shipengine/react-api
TypeScript icon, indicating that this package has built-in type declarations

4.3.5 • Public • Published

ShipEngine React Api

The shipengine/react-api library provides React bindings for the shipengine/js-api client, with the addition of data sharing and cache management via React Query (hereon "RQ").

The client interface is exposed via hooks[^1] sharing a single RQ client instance; this allows multiple components to access data from the same ShipEngine API endpoint with a single network request.

For instance, if ComponentAComponentB and ComponentC separately invoke the useListShipments hook on a single render, the API requests will be deduped to a single GET /v1/shipments, with all three components sharing the data / loading / error / etc states from the RQ cache. Revalidating the request in one component similarly updates the others.

Basic usage

import { ShipEngine, useListShipments } from "@shipengine/react-api";

const MyComponent = () => {
  const { data, isLoading, error } = useListShipments();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>{error.message}</div>;

  console.log(data);
  // > an object matching the response schema of https://shipengine.github.io/shipengine-openapi/#operation/list_shipments

  return <div>Retrieved {data.shipments.length} shipments</div>;
};

const MyApp = () => {
  return (
    <ShipEngine getToken={() => "your-platform-token"}>
      <MyComponent />
      <MyComponent />
      <MyComponent />
      {/* All three components will share the same data and only 1 request will be made */}
    </ShipEngine>
  );
};

/@shipengine/react-api/

    Package Sidebar

    Install

    npm i @shipengine/react-api

    Weekly Downloads

    116

    Version

    4.3.5

    License

    none

    Unpacked Size

    330 kB

    Total Files

    148

    Last publish

    Collaborators

    • brock.bouchard.auctane
    • agustin.martin.auctane
    • shipengine_it
    • kaseycantu-se
    • joshuaflanagan
    • prasadjoshi29
    • binkard-auctane
    • lzhang
    • dlblom
    • rickyr
    • uiuxdeveloper
    • dbernazal
    • auc-rhibbeler
    • harris.butler
    • jeffrysparrow
    • ckroutterauctane
    • luxehahn
    • chunter-auctane
    • arapicki
    • romofel
    • bibhusan-shah
    • auctane.joshua.semar
    • christian.casado
    • sushithegreat
    • auctome
    • arjun.modi
    • ddygas
    • deeepawesome
    • lukasz.parala
    • pspringerauct
    • akowalczyk
    • dangnguyen91
    • krzysztof.malcher
    • marcin_karwat_auctane
    • maciej_adamek
    • mspiaczka-auctane
    • bartoszzurawski
    • mmilowska
    • bmusielak
    • kdobrzynskiactn
    • maciej_sabik_auctane
    • zjaholkowska