cleanup: do initialization in componentDidMount instead of render
This commit is contained in:
parent
2cda6d8f35
commit
31c13adaba
1 changed files with 8 additions and 9 deletions
|
@ -98,16 +98,19 @@ export default class AutoHideScrollbar extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
installBodyClassesIfNeeded();
|
||||||
|
this._needsOverflowListener =
|
||||||
|
document.body.classList.contains("mx_scrollbar_nooverlay");
|
||||||
|
if (this._needsOverflowListener) {
|
||||||
|
this.containerRef.addEventListener("overflow", this.onOverflow);
|
||||||
|
this.containerRef.addEventListener("underflow", this.onUnderflow);
|
||||||
|
}
|
||||||
this.checkOverflow();
|
this.checkOverflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
_collectContainerRef(ref) {
|
_collectContainerRef(ref) {
|
||||||
if (ref && !this.containerRef) {
|
if (ref && !this.containerRef) {
|
||||||
this.containerRef = ref;
|
this.containerRef = ref;
|
||||||
if (this._needsOverflowListener) {
|
|
||||||
this.containerRef.addEventListener("overflow", this.onOverflow);
|
|
||||||
this.containerRef.addEventListener("underflow", this.onUnderflow);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (this.props.wrappedRef) {
|
if (this.props.wrappedRef) {
|
||||||
this.props.wrappedRef(ref);
|
this.props.wrappedRef(ref);
|
||||||
|
@ -115,17 +118,13 @@ export default class AutoHideScrollbar extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (this.containerRef) {
|
if (this._needsOverflowListener && this.containerRef) {
|
||||||
this.containerRef.removeEventListener("overflow", this.onOverflow);
|
this.containerRef.removeEventListener("overflow", this.onOverflow);
|
||||||
this.containerRef.removeEventListener("underflow", this.onUnderflow);
|
this.containerRef.removeEventListener("underflow", this.onUnderflow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
installBodyClassesIfNeeded();
|
|
||||||
if (this._needsOverflowListener === null) {
|
|
||||||
this._needsOverflowListener = document.body.classList.contains("mx_scrollbar_nooverlay");
|
|
||||||
}
|
|
||||||
return (<div
|
return (<div
|
||||||
ref={this._collectContainerRef}
|
ref={this._collectContainerRef}
|
||||||
className={["mx_AutoHideScrollbar", this.props.className].join(" ")}
|
className={["mx_AutoHideScrollbar", this.props.className].join(" ")}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue