Skip to content

Instantly share code, notes, and snippets.

@blvdmitry
Last active December 13, 2018 19:51
Show Gist options
  • Save blvdmitry/6b7baceba1da75d1d95b08ed79db1b52 to your computer and use it in GitHub Desktop.
Save blvdmitry/6b7baceba1da75d1d95b08ed79db1b52 to your computer and use it in GitHub Desktop.
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