Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

like image 722
Shira Avatar asked May 18 '26 19:05

Shira


1 Answers

Props generic should go as a second argument, not the first.

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

like image 156
captain-yossarian Avatar answered May 20 '26 13:05

captain-yossarian