React Native 中如何像原生平台一样实现组件继承?

How to do component inheritance in React Native like on native platform?

我的背景是 iOS 开发人员,在 swift 我可以做 MyInput: UITextField(swift React Native Input 的替代组件)。 这意味着 MyInput 自动获得了 UITextField 拥有的所有属性和功能。目前在本机反应中我这样做是这样的:

interface Props {
    title?: string;
    text: string;
    onChangeText?: (string) => void;
    keyboardType?: KeyboardTypeOptions;
    disabled?: boolean;
    onBlur?: () => void;
}

export default function MyInput ({
    title, text, onChangeText, keyboardType, disabled = false, onBlur= (()=> null)}: Props)
{

return(
    <Input
        label={title}
        onChangeText={(text) => onChangeText(text)}
        value={text}
        keyboardType={keyboardType}
        disabled={disabled}
        onBlur={() => onBlur()}
    />);

基本上我必须将我想要的任何东西从 Input 添加到 Props 中,然后将其重定向到 Input 中。有没有一种方法可以在不将大部分代码加倍的情况下升级 Input,并在 MyInput 中默认提供所有 Input 属性?

因此必须重写像 onBlur 这样的方法。

或者,如果有人至少可以告诉我如何 google 找到这样的解决方案?

如果我猜对了,这就是你要找的东西

export default function MyInput (props: Props) // get all the props
{

const myProps = { // change the key value pairs according to props that Input accepts
    ...props,
    label: props.text,
    value: props.text
}

return(
    <Input
        {...myProps}
    />);

如果不是请告诉我,我会相应地更改它。