Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

getting error on form onSubmit because of wrong type in react typescript

I have the below function and when I pass the function into another component I need to define the type of updateChannelInfo but my type is showing wrong,

const updateChannelInfo = (event: React.FormEvent<HTMLFormElement>) => {
    event.preventDefault();
    updateTitle(channelTitle);
    selectedGame && updateChannelGame(selectedGame);
  };

I am getting error on onSubmit

interface EditChannelInfo {
  updateChannelInfo: React.FormEvent<HTMLFormElement>;
}

const EditChannelInfoCollapse = (props: EditChannelInfo): ReactElement => {
 <form onSubmit={updateChannelInfo}>
 ...
 </form>

}

Error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(property) DOMAttributes<HTMLFormElement>.onSubmit?: React.FormEventHandler<HTMLFormElement> | undefined
Type 'FormEvent<HTMLFormElement>' is not assignable to type 'FormEventHandler<HTMLFormElement>'.
  Type 'FormEvent<HTMLFormElement>' provides no match for the signature '(event: FormEvent<HTMLFormElement>): void'.ts(2322)
index.d.ts(1384, 9): The expected type comes from property 'onSubmit' which is declared here on type 'DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>'

>Solution :

This

interface EditChannelInfo {
  updateChannelInfo: React.FormEvent<HTMLFormElement>;
}

should be

interface EditChannelInfo {
  updateChannelInfo: (event: React.FormEvent<HTMLFormElement>) => void;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading