I have this component:
const TheBarTitle = (
theClass: any,
columnTitle: string,
onClickAction: any,
) => {
return (
<div
className={theClass}
title="Click to add this filter"
onClick={onClickAction}
>
{columnTitle}
</div>
);
};
Which is used this way:
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:',
)
}
/>
),
....
However I get the error: Tag 'TheBarTitle' expects at least '3' arguments, but the JSX factory 'React.createElement' provides at most '2'. TS622
I am using actually 3 arguments. Any idea what I am doing wrong and it sees only 2?
You are mixing function call with compoent creation methods.
Change TheBarTitle
to a FunctionComponent creation method
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>
)
}
Or your call to the function to this:
title: TheBarTitle(classes.contentxyz, "THIS IS THE TITLE", (e: any) =>
this.handleTooltip(e, 'theeetitle:')
))
For the latter I would suggest to also change the casing on the naming.
Complementary answer to the above one:
const TheBarTitle = (
theClass: any,
columnTitle: string,
onClickAction: any,
) => {
return ( ... );
};
For a component: What you have between your parentheses are arguments which we provide to functions, whereas React is expecting only 2 possible values ( objects ) ==> hence no values as params like quoted in the above )
What you want to do is using:
It should have been:
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 ( ... ); };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With