import { Code } from "@/components/code"; export const metadata = { title: "@json-render/react API | json-render", }; export default function ReactApiPage() { return (

@json-render/react

React components, providers, and hooks.

Providers

DataProvider

{` {children} `}

ActionProvider

{`}> {children} type ActionHandler = (params: Record) => void | Promise;`}

VisibilityProvider

{` {children} interface AuthState { isSignedIn: boolean; roles?: string[]; }`}

ValidationProvider

{`}> {children} type ValidatorFn = (value: unknown, args?: object) => boolean | Promise;`}

defineRegistry

Create a type-safe component registry from a catalog. Components receive{" "} props,{" "} children,{" "} onAction, and{" "} loading with catalog-inferred types.

{`import { defineRegistry } from '@json-render/react'; const { registry } = defineRegistry(catalog, { components: { Card: ({ props, children }) =>
{props.title}{children}
, Button: ({ props, onAction }) => ( ), }, }); // Pass to `}

Components

Renderer

{` type Registry = Record>;`}

Component Props (via defineRegistry)

{`interface ComponentContext

{ props: P; // Typed props from catalog children?: React.ReactNode; // Rendered children (for slot components) onAction?: (action: { name: string; params?: object }) => void; loading?: boolean; }`}

Hooks

useUIStream

{`const { spec, // Spec | null - current UI state isStreaming, // boolean - true while streaming error, // Error | null send, // (prompt: string, context?: Record) => Promise clear, // () => void - reset spec and error } = useUIStream({ api: string, // API endpoint URL onComplete?: (spec: Spec) => void, // Called when streaming completes onError?: (error: Error) => void, // Called when an error occurs });`}

useData

{`const { data, // Record setData, // (data: object) => void getValue, // (path: string) => unknown setValue, // (path: string, value: unknown) => void } = useData();`}

useDataValue

{`const value = useDataValue(path: string);`}

useDataBinding

{`const [value, setValue] = useDataBinding(path: string);`}

useActions

{`const { dispatch } = useActions(); // dispatch(actionName: string, params: object)`}

useAction

{`const submitForm = useAction('submit_form'); // submitForm(params: object)`}

useIsVisible

{`const isVisible = useIsVisible(condition?: VisibilityCondition);`}

useFieldValidation

{`const { value, // unknown setValue, // (value: unknown) => void errors, // string[] validate, // () => Promise isValid, // boolean } = useFieldValidation(path: string, checks: ValidationCheck[]);`}
); }