Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Created June 26, 2017 03:42
Show Gist options
  • Save mikebridge/8727ecf8f32b9dde63055a52b8c2c85e to your computer and use it in GitHub Desktop.
Save mikebridge/8727ecf8f32b9dde63055a52b8c2c85e to your computer and use it in GitHub Desktop.
listen to react mouseover events with rxjs
class MouseOverComponent extends React.Component {
componentDidMount() {
this.mouseMove$ = Rx.Observable.fromEvent(this.mouseDiv, "mousemove")
.throttleTime(1000)
.subscribe(() => console.log("throttled mouse move"));
}
componentWillUnmount() {
this.mouseMove$.unsubscribe();
}
render() {
return (
<div ref={(ref) => this.mouseDiv = ref}>
Move the mouse and look at the console...
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment