Created
June 26, 2017 03:42
-
-
Save mikebridge/8727ecf8f32b9dde63055a52b8c2c85e 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