React Typescript Error
Unanswered
Snowy Plover posted this in #help-forum
Snowy PloverOP
This is my code:
I am having an error which says Type '(e: ChangeEvent<HTMLInputElement>) => void' is not assignable to type '(e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void'. ...
Please help me resolve this, I don't understand the problem
interface InputFieldProps{
type: string,
onChange: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void,
placeholder: string,
required?: boolean
}
const InputField: React.FC<InputFieldProps> = ({type, onChange, placeholder, required}) => {
return(
<input type={type} onChange={onChange} required={required} placeholder={placeholder}
className='border border-gray-400 p-2 mb-4 rounded-lg w-full'/>
)
}
const InputTitle = (onChange: (e: ChangeEvent<HTMLInputElement>) => void) => {
return(
<InputField type="text" onChange={onChange} required placeholder="Task name"/>
)
}
const InputDesc = (onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void) => {
return(
<InputField type="textarea" onChange={onChange} required placeholder="Task name"/>
)
}I am having an error which says Type '(e: ChangeEvent<HTMLInputElement>) => void' is not assignable to type '(e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void'. ...
Please help me resolve this, I don't understand the problem