React + TSのformのonSubmitで値を取得

サンプルコード

const onSubmit = (ev: React.FormEvent<HTMLFormElement>) => { ev.preventDefault(); const target = ev.target as typeof ev.target & { t1: { value: string }; t2: { value: string }; }; console.log(target.t1.value); console.log(target.t2.value);
};
return ( <div className="App"> <form onSubmit={(ev) => onSubmit(ev)}> <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="submit" /> </form> </div>
);

参考