react-native by vercel-labs/json-render
npx skills add https://github.com/vercel-labs/json-render --skill react-native一个 React Native 渲染器,能够将 JSON 规范转换为使用标准组件、数据绑定、可见性控制、操作和动态属性的原生移动端组件树。
import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/react-native/schema";
import {
standardComponentDefinitions,
standardActionDefinitions,
} from "@json-render/react-native/catalog";
import { defineRegistry, Renderer, type Components } from "@json-render/react-native";
import { z } from "zod";
// 使用标准 + 自定义组件创建目录
const catalog = defineCatalog(schema, {
components: {
...standardComponentDefinitions,
Icon: {
props: z.object({ name: z.string(), size: z.number().nullable(), color: z.string().nullable() }),
slots: [],
description: "图标显示",
},
},
actions: standardActionDefinitions,
});
// 仅注册自定义组件(标准组件已内置)
const { registry } = defineRegistry(catalog, {
components: {
Icon: ({ props }) => <Ionicons name={props.name} size={props.size ?? 24} />,
} as Components<typeof catalog>,
});
// 渲染
function App({ spec }) {
return (
<StateProvider initialState={{}}>
<VisibilityProvider>
<ActionProvider handlers={{}}>
<Renderer spec={spec} registry={registry} />
</ActionProvider>
</VisibilityProvider>
</StateProvider>
);
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
Container - 带有内边距、背景和边框半径的包装器Row - 带有间距和对齐方式的水平弹性布局Column - 带有间距和对齐方式的垂直弹性布局ScrollContainer - 可滚动区域(垂直或水平)SafeArea - 为刘海屏/主页指示器提供安全区域边距Pressable - 可触摸包装器,按下时触发操作Spacer - 固定或灵活的间距Divider - 细线分隔符Heading - 标题文本(1-6 级)Paragraph - 正文文本Label - 小型标签文本Image - 带有尺寸模式的图像显示Avatar - 圆形头像图像Badge - 小型状态徽章Chip - 用于分类的标签/芯片Button - 带有变体的可按下按钮TextInput - 文本输入框Switch - 切换开关Checkbox - 带标签的复选框Slider - 范围滑块SearchBar - 搜索输入框Spinner - 加载指示器ProgressBar - 进度指示器Card - 带有可选标题的卡片容器ListItem - 带有标题、副标题和辅助视图的列表行Modal - 底部工作表模态框在元素上使用 visible 属性。语法:{ "$state": "/path" }、{ "$state": "/path", "eq": value }、{ "$state": "/path", "not": true },使用 [ cond1, cond2 ] 表示 AND 逻辑。
将 Pressable 与内置的 setState 操作结合使用,用于实现交互式 UI(如标签栏):
{
"type": "Pressable",
"props": {
"action": "setState",
"actionParams": { "statePath": "/activeTab", "value": "home" }
},
"children": ["home-icon", "home-label"]
}
任何属性值都可以是数据驱动的表达式,在渲染时解析:
{ "$state": "/state/key" } - 从状态模型中读取(单向读取){ "$bindState": "/path" } - 双向绑定:用于表单组件的自然值属性(value、checked、pressed 等)。{ "$bindItem": "field" } - 与重复项字段的双向绑定。在重复作用域内使用。{ "$cond":<condition>, "$then": <value>, "$else": <value> } - 条件值{
"type": "TextInput",
"props": {
"value": { "$bindState": "/form/email" },
"placeholder": "邮箱"
}
}
组件不使用 statePath 属性进行双向绑定。请改为在自然值属性上使用 { "$bindState": "/path" }。
setState 操作由 ActionProvider 自动处理,并直接更新状态模型,这会重新评估可见性条件和动态属性表达式:
{ "action": "setState", "actionParams": { "statePath": "/activeTab", "value": "home" } }
| 提供者 | 用途 |
|---|---|
StateProvider | 在组件之间共享状态(JSON Pointer 路径)。接受可选的 store 属性用于受控模式。 |
ActionProvider | 处理从组件派发的操作 |
VisibilityProvider | 启用基于状态的条件渲染 |
ValidationProvider | 表单字段验证 |
将 StateStore 传递给 StateProvider(或 JSONUIProvider / createRenderer)以使用外部状态管理:
import { createStateStore, type StateStore } from "@json-render/react-native";
const store = createStateStore({ count: 0 });
<StateProvider store={store}>{children}</StateProvider>
store.set("/count", 1); // React 会自动重新渲染
当提供了 store 时,initialState 和 onStateChange 将被忽略。
| 导出项 | 用途 |
|---|---|
defineRegistry | 从目录创建类型安全的组件注册表 |
Renderer | 使用注册表渲染规范 |
schema | React Native 元素树模式 |
standardComponentDefinitions | 所有标准组件的目录定义 |
standardActionDefinitions | 标准操作的目录定义 |
standardComponents | 预构建的组件实现 |
createStandardActionHandlers | 为标准操作创建处理器 |
useStateStore | 访问状态上下文 |
useStateValue | 从状态获取单个值 |
useBoundProp | 通过 $bindState/$bindItem 进行双向状态绑定 |
useStateBinding | (已弃用) 旧版按路径双向绑定 |
useActions | 访问操作上下文 |
useAction | 获取单个操作分发函数 |
useUIStream | 从 API 端点流式传输规范 |
createStateStore | 创建与框架无关的内存 StateStore |
StateStore | 用于接入外部状态管理的接口 |
每周安装量
237
代码仓库
GitHub 星标数
13.3K
首次出现
2026年3月7日
安全审计
安装于
codex231
cursor227
opencode227
gemini-cli226
kimi-cli226
amp226
React Native renderer that converts JSON specs into native mobile component trees with standard components, data binding, visibility, actions, and dynamic props.
import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/react-native/schema";
import {
standardComponentDefinitions,
standardActionDefinitions,
} from "@json-render/react-native/catalog";
import { defineRegistry, Renderer, type Components } from "@json-render/react-native";
import { z } from "zod";
// Create catalog with standard + custom components
const catalog = defineCatalog(schema, {
components: {
...standardComponentDefinitions,
Icon: {
props: z.object({ name: z.string(), size: z.number().nullable(), color: z.string().nullable() }),
slots: [],
description: "Icon display",
},
},
actions: standardActionDefinitions,
});
// Register only custom components (standard ones are built-in)
const { registry } = defineRegistry(catalog, {
components: {
Icon: ({ props }) => <Ionicons name={props.name} size={props.size ?? 24} />,
} as Components<typeof catalog>,
});
// Render
function App({ spec }) {
return (
<StateProvider initialState={{}}>
<VisibilityProvider>
<ActionProvider handlers={{}}>
<Renderer spec={spec} registry={registry} />
</ActionProvider>
</VisibilityProvider>
</StateProvider>
);
}
Container - wrapper with padding, background, border radiusRow - horizontal flex layout with gap, alignmentColumn - vertical flex layout with gap, alignmentScrollContainer - scrollable area (vertical or horizontal)SafeArea - safe area insets for notch/home indicatorPressable - touchable wrapper that triggers actions on pressSpacer - fixed or flexible spacingDivider - thin line separatorHeading - heading text (levels 1-6)Paragraph - body textLabel - small label textImage - image display with sizing modesAvatar - circular avatar imageBadge - small status badgeChip - tag/chip for categoriesButton - pressable button with variantsTextInput - text input fieldSwitch - toggle switchCheckbox - checkbox with labelSlider - range sliderSearchBar - search inputSpinner - loading indicatorProgressBar - progress indicatorCard - card container with optional headerListItem - list row with title, subtitle, accessoryModal - bottom sheet modalUse visible on elements. Syntax: { "$state": "/path" }, { "$state": "/path", "eq": value }, { "$state": "/path", "not": true }, [ cond1, cond2 ] for AND.
Use Pressable with the built-in setState action for interactive UIs like tab bars:
{
"type": "Pressable",
"props": {
"action": "setState",
"actionParams": { "statePath": "/activeTab", "value": "home" }
},
"children": ["home-icon", "home-label"]
}
Any prop value can be a data-driven expression resolved at render time:
{ "$state": "/state/key" } - reads from state model (one-way read)
{ "$bindState": "/path" } - two-way binding: use on the natural value prop (value, checked, pressed, etc.) of form components.
{ "$bindItem": "field" } - two-way binding to a repeat item field. Use inside repeat scopes.
{ "$cond":<condition>, "$then": <value>, "$else": <value> } - conditional value
{ "type": "TextInput", "props": { "value": { "$bindState": "/form/email" }, "placeholder": "Email" } }
Components do not use a statePath prop for two-way binding. Use { "$bindState": "/path" } on the natural value prop instead.
The setState action is handled automatically by ActionProvider and updates the state model directly, which re-evaluates visibility conditions and dynamic prop expressions:
{ "action": "setState", "actionParams": { "statePath": "/activeTab", "value": "home" } }
| Provider | Purpose |
|---|---|
StateProvider | Share state across components (JSON Pointer paths). Accepts optional store prop for controlled mode. |
ActionProvider | Handle actions dispatched from components |
VisibilityProvider | Enable conditional rendering based on state |
ValidationProvider | Form field validation |
Pass a StateStore to StateProvider (or JSONUIProvider / createRenderer) to use external state management:
import { createStateStore, type StateStore } from "@json-render/react-native";
const store = createStateStore({ count: 0 });
<StateProvider store={store}>{children}</StateProvider>
store.set("/count", 1); // React re-renders automatically
When store is provided, initialState and onStateChange are ignored.
| Export | Purpose |
|---|---|
defineRegistry | Create a type-safe component registry from a catalog |
Renderer | Render a spec using a registry |
schema | React Native element tree schema |
standardComponentDefinitions | Catalog definitions for all standard components |
standardActionDefinitions | Catalog definitions for standard actions |
standardComponents |
Weekly Installs
237
Repository
GitHub Stars
13.3K
First Seen
Mar 7, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex231
cursor227
opencode227
gemini-cli226
kimi-cli226
amp226
Hugging Face Jobs:云端运行AI工作负载,无需本地GPU,支持数据处理、批量推理和模型训练
232 周安装
MCP服务器构建器:快速创建生产就绪的MCP服务器与ChatGPT小组件
314 周安装
Mapbox样式质量检查与优化工具 - 验证、可访问性、性能优化指南
384 周安装
PDF 生成器 - Deno 自动化 PDF 创建、填充、合并与处理工具
355 周安装
Azure镜像构建器教程:使用Packer创建Azure托管镜像和计算库镜像
346 周安装
Qdrant向量数据库Java集成指南:Spring Boot与LangChain4j语义搜索实战
339 周安装
| Pre-built component implementations |
createStandardActionHandlers | Create handlers for standard actions |
useStateStore | Access state context |
useStateValue | Get single value from state |
useBoundProp | Two-way state binding via $bindState/$bindItem |
useStateBinding | (deprecated) Legacy two-way binding by path |
useActions | Access actions context |
useAction | Get a single action dispatch function |
useUIStream | Stream specs from an API endpoint |
createStateStore | Create a framework-agnostic in-memory StateStore |
StateStore | Interface for plugging in external state management |