我有这样的组成部分:
const TheBarTitle = (
theClass: any,
columnTitle: string,
onClickAction: any,
) => {
return (
<div
className={theClass}
title="Click to add this filter"
onClick={onClickAction}
>
{columnTitle}
</div>
);
};
它是这样使用的:
render: (rowData): any => {
return (
<div className={classes.contentxyz}>
......... </div>
);
},
},
{
title: (
<TheBarTitle
theClass={classes.contentxyz}
columnTitle="THIS IS THE TITLE"
onClickAction={(e: any) =>
this.handleTooltip(
e,
'theeetitle:',
)
}
/>
),
....
但是,我得到了错误:Tag 'TheBarTitle' expects at least '3' arguments, but the JSX factory 'React.createElement' provides at most '2'. TS622
我实际上使用了3个参数。你知不知道我做错了什么而它只看到了2?
发布于 2021-02-15 12:25:10
您将函数调用与组合创建方法混合在一起。将TheBarTitle
更改为FunctionComponent创建方法
interface Props {
theClass: any
columnTitle: string
onClickAction: any
}
const TheBarTitle: React.FC<Props> = ({theClass, columnTitle, onClickAction}) => {
return (
<div
className={theClass}
title="Click to add this filter"
onClick={onClickAction}
>
{columnTitle}
</div>
)
}
或者调用此函数:
title: TheBarTitle(classes.contentxyz, "THIS IS THE TITLE", (e: any) =>
this.handleTooltip(e, 'theeetitle:')
))
对于后者,我建议也更改命名的大小写。
发布于 2021-07-19 15:11:04
对上述问题的补充答复:
const TheBarTitle = (
theClass: any,
columnTitle: string,
onClickAction: any,
) => {
return ( ... );
};
对于组件:括号之间的参数是我们提供给函数的参数,而React只期望两个可能的值(对象) ==>,因此没有像上面引用的那样的值作为参数)。
object
您要做的是使用:
。
它应该是:
interface Props {
theClass: any
columnTitle: string
onClickAction: any
}
// Regular
const TheBarTitle = ( props: Props ) => {
const { ... } = props // or props.[YOUR PROPS] to access your named props
return ( ... );
};
// Destructuring version
const TheBarTitle = ({
theClass,
columnTitle,
onClickAction,
} : Props ) => { return ( ... ); };
https://stackoverflow.com/questions/66207765
复制相似问题