Skip to content

Instantly share code, notes, and snippets.

@gapurov
Forked from mikebridge/mouseOverComponent.tsx
Created March 18, 2018 14:12
Show Gist options
  • Save gapurov/d5c3fdc2157e2b1c91777444df751551 to your computer and use it in GitHub Desktop.
Save gapurov/d5c3fdc2157e2b1c91777444df751551 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