Typescript: React event types

前端 未结 8 917
故里飘歌
故里飘歌 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:11

    I think the simplest way is that:

    type InputEvent = React.ChangeEvent;
    type ButtonEvent = React.MouseEvent;
    
    update = (e: InputEvent): void => this.props.login[e.target.name] = e.target.value;
    submit = (e:  ButtonEvent): void => {
        this.props.login.logIn();
        e.preventDefault();
    }
    

提交回复
热议问题