-1

Here is my template and code:

const submit = (event: React.MouseEventHandler<HTMLButtonElement>) => {
   console.log("submitted");
};

template:

<input type="password" defaultValue={repass} onChange={(e) => handleChange(e)} placeholder="userPassword Repeat" name="userPasswordRep" />
  <button disabled={isSubmit} onClick={submit(event)}>
    Sign Up{" "}
  </button>

here handleChange works. even the button works if I return using another function. but need know why can't we directly call the submit method from template, what is behind?

getting error and warnings:

'event' is deprecated.ts(6385) Unexpected use of 'event'.

Dale K
  • 25,246
  • 15
  • 42
  • 71
user2024080
  • 1
  • 14
  • 56
  • 96
  • Please search for warnings before asking questions. Read warnings, don't ignore them. And you should learn to recognize the difference between a warning and an error. [I'm trying to call event but my Visual Code say ("event is deprecated ts(6385)")](https://stackoverflow.com/questions/64585035/im-trying-to-call-event-but-my-visual-code-say-event-is-deprecated-ts6385) – Andy Ray Dec 10 '22 at 05:09
  • Because that's not html its just javascript objects. for example, ` – Dilshan Dec 10 '22 at 05:10

1 Answers1

2

You don't need to call pass the event explicitly here

 <button disabled={isSubmit} onClick={submit}>

which is similar to this

<button disabled={isSubmit} onClick={() => submit(event)}>
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80