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
| // HOC that will add mouse position to Wrapped components props | |
| const WithMouse = WrappedComponent => | |
| class extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { mouseX: 0, mouseY: 0 }; | |
| } | |
| onMouseMove = e => { | |
| this.setState({ mouseX: e.clientX, mouseY: e.clientY }); | |
| }; |
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
| // Simple mixin that listens to mouse events and | |
| // sets the state everytime the mouse position changes | |
| var MousePosMixin = { | |
| getInitialState() { | |
| return { mouseX: 0, mouseY: 0 } | |
| }, | |
| onMouseMove(e) { | |
| this.setState({ mouseX: e.clientX, mouseY: e.clientY }); | |
| }, | |
| componentDidMount() { |
NewerOlder