Created
June 13, 2018 07:17
-
-
Save hg-pyun/0c728fd9605f69deea436ff20988bce6 to your computer and use it in GitHub Desktop.
This file contains 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
// The <Mouse> component encapsulates the behavior we need... | |
class Mouse extends React.Component { | |
constructor(props) { | |
super(props); | |
this.handleMouseMove = this.handleMouseMove.bind(this); | |
this.state = { x: 0, y: 0 }; | |
} | |
handleMouseMove(event) { | |
this.setState({ | |
x: event.clientX, | |
y: event.clientY | |
}); | |
} | |
render() { | |
return ( | |
<div style={{ height: '100%' }} onMouseMove={this.handleMouseMove}> | |
{/* ...but how do we render something other than a <p>? */} | |
<p>The current mouse position is ({this.state.x}, {this.state.y})</p> | |
</div> | |
); | |
} | |
} | |
class MouseTracker extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h1>Move the mouse around!</h1> | |
<Mouse /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment