Skip to content

Instantly share code, notes, and snippets.

View cjkihl's full-sized avatar

Carl-Johan Kihl cjkihl

View GitHub Profile
@cjkihl
cjkihl / WithMouse.js
Last active April 29, 2018 06:10
HOC Example WithMouse
// 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 });
};
@cjkihl
cjkihl / MixinExample.js
Last active April 29, 2018 05:44
React Mixin Example
// 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() {