React-将元素RadioButton传递给React Pure组件

问题描述

我是TypeScript和React编码的新手,所以如果以前在其他地方提出过这个问题,请原谅我。我想做的是有一个扩展React.PureComponent的类,该类接受一个RadioButton元素,如下所示:

    export class RadioGroup extends React.PureComponent<{ radioButton: RadioButton,isValid?: boolean }>
{
    render = () => (
        <div className="p-inputgroup">
            {this.props.radioButton}
            <div className="p-inputgroup-addon input">
                {this.props.children}
            </div>
        </div>
    )
}

要传递给此组件的代码如下:

 const lastNRadio =  () =>
                        (
                        <RadioButton
                            inputId="LastN"
                            value="val1"
                            name="SearchType"
                            onChange={(e) => OnChange(e.value.value)}
                            
                        />
                        );
 const { lastNDaysOption,chassisOption,sequenceOption,rakeOption,baselinesOnlyOption,calendarOption,minRunNumberOption,maxRunNumberOption } = 
    {                    
        lastNDaysOption: (
            <RadioGroup radioButton={lastNRadio}  title="Last N Days" >           
                <SpinBox
                    value={localLastNDays}
                    onChange={setLocalLastNDays}
                    min={0}
                    max={999}
                />            
            </RadioGroup>
        )};

但是我一直遇到的错误是

Overload 1 of 2,'(props: Readonly<{ radioButton: RadioButton; isValid?: boolean | undefined; }>): RadioGroup',gave the following error.
    Type '() => Element' is missing the following properties from type 'RadioButton': context,setState,forceUpdate,render,and 3 more.
  Overload 2 of 2,'(props: { radioButton: RadioButton; isValid?: boolean | undefined; },context?: any): RadioGroup',gave the following error.
    Type '() => JSX.Element' is not assignable to type 'RadioButton'.ts(2769) 

我尝试将RadioButton强制转换为JSX.Element,但对此一无所知。似乎应该可行并且很简单,但是我在这里转圈。任何想法/帮助将不胜感激。

亲切的问候

史蒂夫

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...