Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed React event handler #66

Open
ccorcos opened this issue Mar 27, 2017 · 1 comment
Open

Typed React event handler #66

ccorcos opened this issue Mar 27, 2017 · 1 comment

Comments

@ccorcos
Copy link

ccorcos commented Mar 27, 2017

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.

@danielkcz
Copy link

Did no one figure this out yet or nobody wants to share ? :)

import React, { MouseEvent } from 'react'

onMouseDown = (event: MouseEvent<HTMLDivElement>) => {
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants