Files
Chris Tate 801708a128 react-native and other things (#81)
* react native

* fixes

* pop/push

* fixes

* rename data -> state

* remove . tsbuildinfo

* fixes

* fixes

* user prompt

* fixes

* $id

* combine catalog.ts

* better actions

* repeat

* fix docs

* fixes

* fixes

* fixes

* better stream

* catalog

* fixes

* fixes

* fixes

* dialog

* sonner

* accordion

* catalog on homepage

* fixes

* more catalog

* fixes

* fixes

* refactor

* mv

* 404

* fixes

* nested

* fixes

* fixes

* fixes

* fixes

* mobile playground

* mdx

* fix mdx

* fixes

* streamdown

* fixes

* use haiku

* fixes

* great

* fixes

* fix ...

* fixes

* fixes

* fix build

* fix lint

* fix lint

* fix lint

* fix tests
2026-02-09 01:31:46 -06:00

48 lines
1.5 KiB
TypeScript

import React, { type ReactNode, useMemo } from "react";
import {
Renderer,
StateProvider,
VisibilityProvider,
ActionProvider,
ValidationProvider,
createStandardActionHandlers,
type Spec,
} from "@json-render/react-native";
import { registry } from "./registry";
// =============================================================================
// AppRenderer
// =============================================================================
interface AppRendererProps {
spec: Spec | null;
loading?: boolean;
}
export function AppRenderer({ spec, loading }: AppRendererProps): ReactNode {
// Seed the StateProvider with any initial state from the spec.
// Memoize so we only pick up the state from the first render of this spec
// (otherwise re-renders during streaming would keep resetting the state).
// NOTE: This hook must be called before any early return to satisfy Rules of Hooks.
const initialState = useMemo(
() => spec?.state ?? {},
// Re-seed when the spec root changes (new generation)
// eslint-disable-next-line react-hooks/exhaustive-deps
[spec?.root],
);
if (!spec) return null;
return (
<StateProvider initialState={initialState}>
<VisibilityProvider>
<ActionProvider handlers={createStandardActionHandlers()}>
<ValidationProvider>
<Renderer spec={spec} registry={registry} loading={loading} />
</ValidationProvider>
</ActionProvider>
</VisibilityProvider>
</StateProvider>
);
}