Typescript input onchange event.target.value

后端 未结 11 935
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 21:25

In my react and typescript app, I use: onChange={(e) => data.motto = (e.target as any).value}.

How do I correctly define the typings for the class, s

11条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 21:52

      function handle_change(
        evt: React.ChangeEvent
      ): string {
        evt.persist(); // This is needed so you can actually get the currentTarget
        const inputValue = evt.currentTarget.value;
    
        return inputValue
      }
    

    And make sure you have "lib": ["dom"] in your tsconfig.

提交回复
热议问题