Typescript: React event types

前端 未结 8 919
故里飘歌
故里飘歌 2020-11-27 11:50

What is the correct type for React events. Initially I just used any for the sake of simplicity. Now, I am trying to clean things up and avoid use of any<

8条回答
  •  一个人的身影
    2020-11-27 12:23

    you can do like this in react

    handleEvent = (e: React.SyntheticEvent) => {
      const simpleInput = (e.target as HTMLInputElement).value;
      //for simple html input values
      const formInput = (e.target as HTMLFormElement).files[0];
      //for html form elements
    }
    

提交回复
热议问题