Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何添加一个';s自己定制的输入组件JSX<;输入/>;要响应电话号码输入PhoneInput?_Reactjs_Typescript_React Forwardref - Fatal编程技术网

Reactjs 如何添加一个';s自己定制的输入组件JSX<;输入/>;要响应电话号码输入PhoneInput?

Reactjs 如何添加一个';s自己定制的输入组件JSX<;输入/>;要响应电话号码输入PhoneInput?,reactjs,typescript,react-forwardref,Reactjs,Typescript,React Forwardref,代码遵循此描述 react电话号码输入允许用户用自己的标签替换其默认的JSX标签,该标签特别需要类型react.ForwardRefExoticComponent,并且需要forwardRef(允许访问) 虽然我相信我已经用myTextInput提供了这一功能,但编译器抱怨: 类型“Element”中缺少属性“$$typeof”,但类型“ForwardRefExoticComponent”中需要属性“$$typeof”inputComponent={ForwardedInput} 这很有效。因为

代码遵循此描述

react电话号码输入
允许用户用自己的标签替换其默认的
JSX标签,该标签特别需要类型
react.ForwardRefExoticComponent
,并且需要
forwardRef
(允许访问

虽然我相信我已经用
myTextInput
提供了这一功能,但编译器抱怨:


类型“Element”中缺少属性“$$typeof”,但类型“ForwardRefExoticComponent”中需要属性“$$typeof”
inputComponent={ForwardedInput}


这很有效。因为现在我的生活非常忙碌,我没有时间详细解释,但我会尽快回到这里。

我很感激你是OP,这个答案可能对你有意义,但解释一下你是如何得出这个答案的可能会有帮助。请至少添加关于这条1车道的基本解释,这将有助于未来的读者更好地理解你们为什么会遇到这个问题,以及为什么这条小路解决了这个问题。你们都是对的,我们将尽快努力做到这一点
import React, { forwardRef, InputHTMLAttributes } from 'react';
import 'react-phone-number-input/style.css'
import PhoneInput from 'react-phone-number-input'

const ForwardedInput = forwardRef<any, InputHTMLAttributes<HTMLInputElement>>(
    (props, ref) => {
        const { onChange, value } = props;
        return (
            <input
                type="text"
                ref={ref}
                onChange={onChange}
                value={value}
            />
        );
    }
);

const MyPhoneInput = () => {

    const ref = React.createRef();
    const myTextInput = <ForwardedInput 
        onChange={() => {}}
        value="string"
        ref={ref}
    />;

    return (
        <div>
            <PhoneInput
                    placeholder="Enter phone number"
                    value={"value"}
                    inputComponent={myTextInput}
                    onChange={() => {
                        return;
                    }}
                />
        </div>
    );
};

export default MyPhoneInput;