context
描述
@silver-formily/react 的所有 Context,可以通过 useContext 消费这些 Context 来实现更复杂的定制化开发。
FormContext
描述
Form 上下文,可以获取当前 Form 实例,等价于 useForm
签名
import type { Form } from '@silver-formily/core'
import type { Context } from 'react'
export declare const FormContext: Context<Form>FieldContext
描述
字段上下文,可以获取当前字段实例,等价于 useField
签名
import type { GeneralField } from '@silver-formily/core'
import type { Context } from 'react'
export declare const FieldContext: Context<GeneralField>SchemaMarkupContext
描述
Schema 标签上下文,主要用于收集 JSX Markup 写法的 Schema 标签,然后转换成标准 JSON Schema
完整的 Schema 协议、属性定义和联动规则请查看 JSON Schema 文档。当前页只说明 @silver-formily/react 暴露出来的 Context。
签名
import type { Schema } from '@silver-formily/json-schema'
import type { Context } from 'react'
export declare const SchemaMarkupContext: Context<Schema>SchemaContext
描述
字段 Schema 上下文,主要用于获取当前字段的 Schema 信息,等价于 useFieldSchema
Schema 类型的完整 API 已迁移到 JSON Schema 文档,本页不重复维护协议细节。站内桥接页见 Schema。
签名
import type { Schema } from '@silver-formily/json-schema'
import type { Context } from 'react'
export declare const SchemaContext: Context<Schema>SchemaExpressionScopeContext
描述
Schema 表达式作用域上下文,等价于 useExpressionScope
签名
import type { Context } from 'react'
export declare const SchemaExpressionScopeContext: Context<any>SchemaComponentsContext
描述
Schema 组件映射表上下文,x-component 传入字符串时会从该映射表中解析组件
签名
import type { SchemaReactComponents } from '@silver-formily/react'
import type { Context } from 'react'
export declare const SchemaComponentsContext: Context<SchemaReactComponents>SchemaOptionsContext
描述
Schema 全局参数上下文,主要用于获取从 createSchemaField 传入的参数
签名
import type { ISchemaFieldReactFactoryOptions } from '@silver-formily/react'
import type { Context } from 'react'
export declare const SchemaOptionsContext: Context<ISchemaFieldReactFactoryOptions>ContextCleaner
描述
清理组件,渲染时会将 Field / Schema 相关的 Context 重置为空值,主要用于隔离上下文,比如 FormProvider 内部会用它避免外层字段上下文泄漏到当前表单。
签名
import type { ReactNode } from 'react'
declare function ContextCleaner(props: { children?: ReactNode }): ReactNode这七个 Context 的运行时初始值均为 null,即使声明中未包含空值,也应在对应 Provider 下读取。ContextCleaner 将六个 Field/Schema 上下文重置为 undefined,不清理 FormContext。