@burojs/react
v0.5.0
Published
Buro: React Provider, hooks, slot adapter, base UI translations, BuroRoutes
Readme
@burojs/react
React bindings for buro: context providers, the list controller, i18n, capabilities and test-id plumbing.
UI-kit agnostic — it deliberately depends on no @burojs/ui-* package, so any renderer can sit on top. Its native data runtime uses @tanstack/react-query internally.
Install
pnpm add @burojs/react @burojs/coreUsage
import { BuroProvider, RouterAdapterProvider, useResourceList } from '@burojs/react';
// `adapter` binds your router — `RouterAdapterProvider`'s docblock has the
// react-router and Next App Router ones. It is required, and goes above
// <BuroProvider>: without it no route matches.
function Root({ app, adapter, children }) {
return (
<RouterAdapterProvider adapter={adapter}>
<BuroProvider app={app}>{children}</BuroProvider>
</RouterAdapterProvider>
);
}
function MyList() {
const list = useResourceList('company');
return (
<ul>
{list.rows.map((r) => (
<li key={r.id}>{String(r.name)}</li>
))}
</ul>
);
}Main exports
BuroProvider— mounts the app runtime, i18n, the data runtime, and the interaction layer: an action dispatcher with a default for every effect (refetchinvalidates the framework's queries,notifyreaches the notification sink a toaster registers,redirectpushes through yourRouterAdapterand skips the page already on screen,setClipboard,download,modal), overridable per key witheffects; the unsaved-changes navigation guard; and the notification sink. Nested scopes and tests useDispatcherProvider/useDispatcher.resolveRoute/useRouteNavigate— the one navigation seam: aRouteDescriptorresolved against the registry and pushed through the mountedRouterAdapter(a document navigation without one). MountRouterAdapterProviderabove<BuroProvider>: the defaultredirectand the navigation guard's "Leave" read the adapter from whereBuroProvidersits, so one mounted inside it is invisible to them and they fall back to full page loads.useNavigationBlocker,useRegisterNavigationGuardDialog,useRegisterNotificationSinkare the hooks a UI kit's form, dialog and toaster use. A hook whose job is to register is nameduseRegister<Thing>, and the most recently registered, still-mounted registrant wins: one toaster receives notifications, one dialog answers a held navigation.useResourceList— the data-connected list controller: rows, pagination (including the unknown-total contract), filters, search, sorting, columns, selection, saved views, routing hrefs, and the on-demand row count.ResourceListProvider/useResourceListContextexpose it to override slots, so a custom list body is testable against a stub controller with no runtime or Next mocking.useApp/useCurrentResource/useCtx— registry and context access.useAction(from@burojs/react/flows) — run a declared flow from code: its state, andrun().useCapability/useCapabilityResolver— the deny-wins capability engine gating fields, actions and columns.useComponent/mergeComponents/ComponentsContext— the component registry behind override slots (list.filters.<resource>,list.cell.<resource>,record.<action>.<resource>,layout.<key>), keys dotted with the canonical resource last.useT/useLocale/I18nContext, plus the built-inen/rulocale bundles — render-time i18n with a live language switch (no reload).TestIdBuilder/TestIdContext— the stable test-id surface shared with@burojs/test-helpers.
License
MIT
