[英]Property 'onClick' does not exist on type '{ children?: ReactNode; }'
I can't seem to find what I'm doing wrong... Any help will be appreciated:我似乎找不到我做错了什么......任何帮助将不胜感激:
type Props = {
onClick: () => void,
value: string
}
const CustomInput = forwardRef<Props>(({ onClick, value }, ref) => (
<div className="react-datepicker-custom-input" onClick={onClick}>
{value}
<i className={classes.arrowDown}></i>
</div>
));
error message: Property 'onClick' does not exist on type '{ children?: ReactNode; }
export default CustomInput;导出默认自定义输入;
Props
generic should go as a second argument, not the first. Props
generic 应该 go 作为第二个参数,而不是第一个。
Example:例子:
type Props = {
onClick: () => void,
value: string
}
type RefType=number
const CustomInput = forwardRef<RefType, Props>(({ onClick, value }, ref) => (
<div className="react-datepicker-custom-input" onClick={onClick}>
{value}
<i className={classes.arrowDown}></i>
</div>
));
First generic argument of forwardRef
is for ref type, second - if for props accordingly forwardRef
的第一个通用参数是 ref 类型,第二个 - 如果相应地用于 props
You can type by adding it this way:您可以通过以下方式添加它:
type Props = {
onClick: () => void,
value: string
}
const CustomInput = forwardRef<Props>(({ onClick, value }:Props, ref:any) => (
<div className="react-datepicker-custom-input" onClick={onClick}>
{value}
<i className={classes.arrowDown}></i>
</div>
));
Try this尝试这个
interface Props { children: ReactNode; onClick: () => void; value: string; } const CustomInput = forwardRef(({ onClick, value }:Props) => ( <div className="react-datepicker-custom-input" onClick={onClick}> {value} <i className={classes.arrowDown}></i> </div> ));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.