Last active
December 13, 2018 19:51
-
-
Save blvdmitry/6b7baceba1da75d1d95b08ed79db1b52 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
class Popover extends React.PureComponent { | |
state = { | |
active: false, | |
visible: false | |
} | |
componentDidMount() { | |
if (this.props.active) { | |
this.show(); | |
} | |
} | |
componentWillReceiveProps({ active }) { | |
if (active !== this.state.active) { | |
if (active) { | |
this.show(); | |
} else { | |
this.hide(); | |
} | |
} | |
} | |
show() { | |
this.setState({ active: true }, () => { | |
// some DOM operations to position popover based on the ref sizes | |
this.setState({ visible: true }); | |
this.props.onShow(); | |
}) | |
} | |
hide() { | |
this.setState({ | |
active: false, | |
visible: false, | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment