如何解决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 举报,一经查实,本站将立刻删除。