Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Last active November 14, 2018 12:14
Show Gist options
  • Save olecksamdr/9700a1784efbdd2a867414a83b28ad5d to your computer and use it in GitHub Desktop.
Save olecksamdr/9700a1784efbdd2a867414a83b28ad5d to your computer and use it in GitHub Desktop.
componentDidUpdate(prevProps, prevState) {
if (isBrowser()) {
const { open, bodyAlign } = this.state;
if (prevState.open !== open) {
const { right } = this.body.current.getBoundingClientRect();
if (right > Root.innerWidth && bodyAlign === 'left') {
// Do not go beyond the right window border
this.setState({ bodyAlign: 'right' });
} else if (right <= Root.innerWidth && bodyAlign === 'right') {
this.setState({ bodyAlign: 'left' });
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment