Last active
June 28, 2018 00:21
-
-
Save nahumzs/f43b768e29e6604c6b091d922eb1b34a to your computer and use it in GitHub Desktop.
RenderPropsExample1
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 from "react"; | |
export default class HoverState extends React.Component { | |
state = { isHover: false }; | |
handleHover = isHover => () => { | |
this.setState({ isHover }); | |
}; | |
render() { | |
return ( | |
<div | |
onMouseOver={this.handleHover(true)} | |
onMouseOut={this.handleHover(false)} | |
> | |
{this.props.render(this.state.isHover)} | |
</div> | |
); | |
} | |
} |
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 from "react"; | |
import HoverState from "./HoverState"; | |
export default class RenderProps extends React.Component { | |
render() { | |
return ( | |
<HoverState | |
render={isHover => { | |
if (isHover) { | |
return <button>🦁</button>; | |
} | |
return <button>🦄</button>; | |
}} | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment