Typescript input onchange event.target.value

后端 未结 11 936
隐瞒了意图╮
隐瞒了意图╮ 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

    Here is a way with ES6 object destructuring, tested with TS 3.3.
    This example is for a text input.

    name: string = '';
    
    private updateName({ target }: { target: HTMLInputElement }) {
        this.name = target.value;
    }
    

提交回复
热议问题