@access-lens/react
v0.1.0
Published
React adapter for Access Lens — typed Provider, AccessGate, and hooks bound to your defineAccessLens config.
Maintainers
Readme
@access-lens/react
React adapter for Access Lens.
Install
pnpm add @access-lens/react @access-lens/coreQuick start
import {
AccessLensProvider,
AccessGate,
permission,
featureFlag,
entitlement,
} from "@access-lens/react";
function App() {
return (
<AccessLensProvider defaultDebugMode={false}>
<Sidebar />
</AccessLensProvider>
);
}
function Sidebar() {
return (
<AccessGate
id="sidebar.billing"
label="Billing"
type="sidebar_item"
reasons={[
permission("billing.read", user.permissions.includes("billing.read")),
featureFlag("billing_v2", flags.billing_v2),
entitlement("billing", tenant.entitlements.billing),
]}
>
<a href="/billing">Billing</a>
</AccessGate>
);
}Behavior
allowed→ renderschildrenunchanged.deniedanddebugMode = false→ rendersfallback(or nothing).deniedanddebugMode = trueandghostInDebug = true→ renderschildrenwrapped in a dashed/ghost style with a tooltip listing the failed reasons and adata-access-lens-idattribute for the overlay.
Hooks
useAccessLens()— returns{ client, debugMode, setDebugMode }.useAccessGate(input)— returns{ node, allowed, denied, unknown }and registers the node into the client.useAccessLensSnapshot()— subscribes to the live snapshot via React'suseSyncExternalStore.
The reason helpers and the core types are re-exported here for convenience so a React app rarely needs to import @access-lens/core directly.
