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

2.8.0 • 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>
  );
};

Readme

Keywords

none

Package Sidebar

Install

npm i @shipengine/react-api

Weekly Downloads

244

Version

2.8.0

License

none

Unpacked Size

209 kB

Total Files

118

Last publish

Collaborators

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