compat
不稳定的组件,用于将 React Native 与 React Strict DOM 元素混合。
警告
这是一个实验性和不稳定的 API,旨在帮助在无法避免在 React Strict DOM 树中嵌套 React Native 元素树的应用程序中逐步采用。
API
native
一个将 React Strict DOM 属性转换为 React Native 属性的组件,然后可以将其传递到自定义 React Native 元素。必须为 nativeProps
提供类型注释,该注释应与正在渲染的 React Native 组件的属性类型匹配。
示例
import { compat } from 'react-strict-dom';
import { Text } from 'react-native';
export component Foo(...props: FooProps) {
return (
<compat.native
{...props}
aria-label="label"
as="text"
>
{(nativeProps: React.PropsOf<Text>)) => (
<Text {...nativeProps} />
)}
</compat.native>
)
}
属性
...reactStrictDOMProps
html.*
元素接受的任何属性。
children: (nativeProps) => React.Node
- 必须是一个函数,它接收计算出的
nativeProps
作为唯一的参数,并返回一个 React Native 元素。
- 必须是一个函数,它接收计算出的
as: 'image' | 'input' | 'text' | 'textarea' | 'view'
- 告诉组件如何转换 native 的属性。 例如,如果渲染到多行
TextInput
,请使用textarea
。 默认为view
。
- 告诉组件如何转换 native 的属性。 例如,如果渲染到多行