React Query hooks for ShipStation API v2 - Type-safe hooks with automatic caching and invalidation
npm install @lecxa/shipstation-react-queryReact Query hooks for ShipStation API v2.
``bash`
npm install @lecxa/shipstation-react-query @tanstack/react-query
Peer dependencies:
- @tanstack/react-query ^5.0.0react
- >=18
`tsx
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function App() {
return (
);
}
`
`tsx
import { useListShipments, useGetShipmentById } from '@lecxa/shipstation-react-query';
function ShipmentsPage() {
const { data, isLoading, error } = useListShipments({ page: 1 });
if (isLoading) return
return (
$3
`tsx
import { useCreateLabel } from '@lecxa/shipstation-react-query';function CreateLabelButton() {
const createLabel = useCreateLabel();
const handleClick = async () => {
const result = await createLabel.mutateAsync({
shipment: { / ... / },
carrier_code: 'stamps_com',
service_code: 'usps_priority_mail',
});
};
return (
);
}
`$3
`tsx
import { useListShipmentsInfinite } from '@lecxa/shipstation-react-query';function InfiniteList() {
const { data, fetchNextPage, hasNextPage } = useListShipmentsInfinite({
page_size: 50,
});
return (
{data?.pages.map((page, i) => (
{page.shipments?.map(s => {s.shipment_id})}
))}
{hasNextPage && }
);
}
`Available Hooks
Query hooks (GET):
-
useListShipments, useListShipmentsInfinite
- useGetShipmentById
- useListLabels, useListLabelsInfinite
- useGetLabelById
- useListCarriers
- useCalculateRates
- And more...Mutation hooks (POST/PUT/DELETE):
-
useCreateLabel
- useCreateShipments
- useVoidLabel
- useCreateBatch`MIT