-
-
Save gapurov/d5c3fdc2157e2b1c91777444df751551 to your computer and use it in GitHub Desktop.
listen to react mouseover events with rxjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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