import Link from "next/link"; import { Code } from "@/components/code"; export const metadata = { title: "Components | json-render", }; export default function ComponentsPage() { return (

Components

Register React components to render your catalog types.

Component Registry

Create a registry that maps catalog component types to React components:

{`const registry = { Card: ({ element, children }) => (

{element.props.title}

{element.props.description && (

{element.props.description}

)} {children}
), Button: ({ element, onAction }) => ( ), };`}

Component Props

Each component receives these props:

{`interface ComponentProps { element: { key: string; type: string; props: Record; children?: UIElement[]; visible?: VisibilityCondition; validation?: ValidationSchema; }; children?: React.ReactNode; // Rendered children onAction: (name: string, params: object) => void; }`}

Using Data Binding

Use hooks to read and write data:

{`import { useDataValue, useDataBinding } from '@json-render/react'; const Metric = ({ element }) => { // Read-only value const value = useDataValue(element.props.valuePath); return (
{element.props.label} {formatValue(value)}
); }; const TextField = ({ element }) => { // Two-way binding const [value, setValue] = useDataBinding(element.props.valuePath); return ( setValue(e.target.value)} placeholder={element.props.placeholder} /> ); };`}

Using the Renderer

{`import { Renderer } from '@json-render/react'; function App() { return ( ); }`}

Next

Learn about data binding for dynamic values.

); }