Skip to content

docs: wrap Renderer in JSONUIProvider in README examples - #445

Open
jitui-123 wants to merge 1 commit into
vercel-labs:mainfrom
jitui-123:docs/wrap-renderer-in-provider
Open

jitui-123 wants to merge 1 commit into
vercel-labs:mainfrom
jitui-123:docs/wrap-renderer-in-provider

Conversation

@jitui-123

Copy link
Copy Markdown

Summary

The React examples in the README render <Renderer> without a provider, which throws at runtime. This wraps them in <JSONUIProvider> and adds a short note on why the provider is required.

Error: useVisibility must be used within a VisibilityProvider
    at useVisibility (...)
    at ReactiveElementRenderer (...)

Refs #443.

Changed

Every snippet that renders <Renderer> for React now includes the provider import and wrapper:

  • Quick Start, section 3 ("Render AI-Generated Specs")
  • React (UI) renderer section
  • shadcn/ui section
  • React Native section — had the same gap and is fixed here too

The Solid example already wrapped correctly and is unchanged, as are the Vue and Svelte sections where <Renderer> appears only in a comment showing template usage.

Why the provider is required

Renderer calls useVisibility(), which throws unless a VisibilityProvider is above it. JSONUIProvider is what supplies that context, along with state, validation, and actions:

<StateProvider>
  <VisibilityProvider>
    <ValidationProvider>
      <ActionProvider>
        ...

The imported JSONUIProvider is available from both @json-render/react and @json-render/react-native.

Verification

Checked out the branch with @json-render/core, @json-render/react, and @json-render/shadcn at 0.21.3, React 19, and Zod 4:

  • Before: a component returning bare <Renderer spec registry /> throws useVisibility must be used within a VisibilityProvider.
  • After: the updated snippet renders.
  • Also searched the README for remaining bare <Renderer> usages — none left outside comments.

Happy to adjust the wording or drop the React Native change if you'd rather keep this PR to the three React snippets.

The React Quick Start rendered <Renderer> on its own, which throws at
runtime:

    Error: useVisibility must be used within a VisibilityProvider

Renderer reads from the state, visibility, validation, and action
contexts that JSONUIProvider supplies, so the provider is required.

Updates the three React snippets in the README (Quick Start, React
renderer section, shadcn/ui section) and the React Native snippet, which
had the same gap. The Solid example was already correctly wrapped.

Refs vercel-labs#443
@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@jitui-123 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread README.md
const { registry } = defineRegistry(catalog, { components });
<Renderer spec={spec} registry={registry} />;

<JSONUIProvider registry={registry} initialState={spec.state ?? {}}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The React TSX example now fails with TS2339 because its locally inferred spec object has no state property, so spec.state ?? {} cannot compile.

Fix on Vercel

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant