BaseField 是一个内部(即未在 index.js 中导出)的基础组件,用于构建更复杂的字段,如 TextField。它为字段组件提供错误处理和焦点样式。它 不 负责组件的布局,除了将字段包裹在 Flex 包装器中之外。
用法
BaseField 主要作为钩子使用,而不是组件:
function useExampleField( props ) {
const { as = 'input', ...baseProps } = useBaseField( props );
const inputProps = {
as,
// more cool stuff here
};
return { inputProps, ...baseProps };
}
function ExampleField( props, forwardRef ) {
const { preFix, affix, disabled, inputProps, ...baseProps } =
useExampleField( props );
return (
<View { ...baseProps } disabled={ disabled }>
{ preFix }
<View autocomplete="off" { ...inputProps } disabled={ disabled } />
{ affix }
</View>
);
}
属性
disabled: boolean
字段是否处于禁用状态。
- 必需:否
hasError: boolean
在组件周围渲染错误样式。
- 必需:否
- 默认值:
false
isInline: boolean
渲染可以内联在某些文本中的组件。
- 必需:否
- 默认值:
false
isSubtle: boolean
渲染组件的微调变体。
- 必需:否
- 默认值:
false