@tbbn/sdk-react
v0.3.0
Published
React hooks for the TBBN Platform API — TbbnProvider, useListing, useOffers, useTradeSession and more.
Downloads
569
Maintainers
Readme
@tbbn/sdk-react
React hooks for the TBBN Platform API. Wrap your app in TbbnProvider once;
every component below it can then read listings, offers, trade sessions and more with a hook,
or reach the full typed client for anything else.
Install
npm install @tbbn/sdk-reactReact 18 or 19 is a peer dependency.
Quick start
import { TbbnProvider, useOffers, useTbbnClient } from '@tbbn/sdk-react';
function App({ sessionToken, sellerId }) {
return (
<TbbnProvider options={{ baseUrl: 'https://api.tbbnetwork.com', accessToken: sessionToken }}>
<OffersInbox sellerId={sellerId} />
</TbbnProvider>
);
}
function OffersInbox({ sellerId }) {
const { data: offers, loading, error, refetch } = useOffers(sellerId, 'received');
const client = useTbbnClient(); // the full @tbbn/sdk-typescript client
if (loading) return <p>Loading…</p>;
if (error) return <p>{error.message}</p>;
return (
<ul>
{offers.map((offer) => (
<li key={offer.id}>
{offer.status}
<button onClick={() => client.offers.accept(offer.id, sellerId).then(refetch)}>
Accept
</button>
</li>
))}
</ul>
);
}A complete example is in example/OffersInbox.tsx.
What's included
TbbnProvider/useTbbnClient()— context plumbing. The provider memoises the client, so it is not rebuilt on every render.useQuery(fn, deps, enabled?)— the fetch-on-mount +refetch()hook every resource hook is built on. Deliberately simple: no caching or deduplication. Swap in TanStack Query or similar if your app needs that.- Resource hooks:
useListing,useListings,useOffers,useTradeSession,useTradeSessions,useRecommendations,useNotifications,useReputationScore. Each waits until its id argument is defined before fetching, so they are safe to call before your session has resolved.
Mutations (create, accept, cancel…) are one-off calls from event handlers, not hooks — use
useTbbnClient() for those.
Support
Questions and bug reports: the developer community.
License
MIT © Trade By Barter Network, Inc.
