Created
September 8, 2017 04:03
-
-
Save prmichaelsen/b8983c188ebf257fc9e1484bdd2c6892 to your computer and use it in GitHub Desktop.
an example of using renderProps as per Michael Jackson's demo
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
import React, { Component } from 'react'; | |
export class Mouse extends React.Component { | |
state = { x: 0, y: 0 }; | |
onMouseMove = (event) => { | |
this.setState( | |
{ x: event.clientX, y: event.clientY } | |
); | |
}; | |
render() { | |
return ( | |
<div onMouseMove={ this.onMouseMove }> | |
{this.props.renderProps(this.state)} | |
</div> | |
); | |
} | |
} | |
export class Text extends React.Component { | |
render() { | |
return ( | |
<Mouse renderProps={(mouse) => { | |
return ( | |
<div> | |
Mouse Position: {mouse.x}, {mouse.y} | |
</div> | |
); | |
}}/>); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment