Last active
June 28, 2016 16:50
-
-
Save samsch/eee175eb0133b4686f8aa54afcbbdc62 to your computer and use it in GitHub Desktop.
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
const React = require('react'); | |
class NewComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.onMouseOver = this.onMouseOver.bind(this); | |
} | |
onMouseOver() { | |
this.props.onMouseOver(this.props.id); | |
} | |
render() { | |
return ( | |
<div onMouseOver={this.onMouseOver} onMouseLeave={this.props.onMouseLeave}> | |
{ props.isHovering ? 'I am being hovered over' : '' } | |
</div> | |
) | |
} | |
} | |
export default NewComponent |
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
const items = [ | |
{ id: 1, name: 'ABC' }, | |
{ id: 2, name: 'EFG' }, | |
{ id: 3, name: 'HIJ' }, | |
] | |
class NewContainer extends Component { | |
contructor(props) { | |
super(props) | |
this.state = { | |
hoverID: null | |
} | |
} | |
handleMouseOver = (id) => { | |
this.setState({ | |
hoverID: id | |
}) | |
} | |
handleMouseLeave = () => { | |
this.setState({ | |
hoverID: null | |
}) | |
} | |
render() { | |
const { hoverID } = this.state | |
return ( | |
{ items.map(item => | |
<NewComponent | |
id={item.id} | |
onMouseOver={this.handleMouseOver} | |
onMouseLeave={this.handleMouseLeave} | |
isHover={hoverID === item.id} /> | |
) } | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment