export const metadata = { title: "Data Binding" } # Data Binding Connect UI components to your application data using JSON Pointer paths. ## JSON Pointer Paths json-render uses JSON Pointer (RFC 6901) for data paths: ```json // Given this data: { "user": { "name": "Alice", "email": "alice@example.com" }, "metrics": { "revenue": 125000, "growth": 0.15 } } // These paths access: "/user/name" -> "Alice" "/metrics/revenue" -> 125000 "/metrics/growth" -> 0.15 ``` ## StateProvider Wrap your app with StateProvider to enable data binding: ```tsx import { StateProvider } from '@json-render/react'; function App() { const initialState = { user: { name: 'Alice' }, form: { email: '', message: '' }, }; return ( {/* Your UI */} ); } ``` ## Reading Data Use `useStateValue` for read-only access: ```tsx import { useStateValue } from '@json-render/react'; function UserGreeting() { const name = useStateValue('/user/name'); return

Hello, {name}!

; } ``` ## Two-Way Binding Use `useStateBinding` for read-write access: ```tsx import { useStateBinding } from '@json-render/react'; function EmailInput() { const [email, setEmail] = useStateBinding('/form/email'); return ( setEmail(e.target.value)} /> ); } ``` ## Using the State Context Access the full state context for advanced use cases: ```tsx import { useStateStore } from '@json-render/react'; function StateDebugger() { const { data, setState, getValue, setValue } = useStateStore(); // Read any path const revenue = getValue('/metrics/revenue'); // Write any path const updateRevenue = () => setValue('/metrics/revenue', 150000); // Replace all state const resetState = () => setState({ user: {}, form: {} }); return
{JSON.stringify(data, null, 2)}
; } ``` ## In JSON UI Trees AI can reference data paths in component props: ```json { "type": "Metric", "props": { "label": "Total Revenue", "valuePath": "/metrics/revenue", "format": "currency" } } ``` ## Next Learn about [actions](/docs/actions) for user interactions.