Skip to content

Typed React event handler #66

Open
@ccorcos

Description

@ccorcos

Seems to me like this should work:

class MouseDown extends React.Component<{}, {}> {
	onMouseDown = (event: MouseEvent) => {
		console.log(event)
	}
	render() {
		return <div onMouseDown={this.onMouseDown} />
	}
}

Ideally I could just leave off the type signature and it would be inferred based on how we're calling it, but that doesnt work. So I don't know how to get this to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions