From 24f422dde3678871b65112b45b8df0cf8f1e22fb Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Thu, 10 Dec 2015 12:30:38 -0800 Subject: Fixed react warning issue with setState in RHS --- web/react/components/rhs_thread.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'web/react') diff --git a/web/react/components/rhs_thread.jsx b/web/react/components/rhs_thread.jsx index 2edcd8b37..945b09e37 100644 --- a/web/react/components/rhs_thread.jsx +++ b/web/react/components/rhs_thread.jsx @@ -17,6 +17,8 @@ export default class RhsThread extends React.Component { constructor(props) { super(props); + this.mounted = false; + this.onChange = this.onChange.bind(this); this.onChangeAll = this.onChangeAll.bind(this); this.forceUpdateInfo = this.forceUpdateInfo.bind(this); @@ -50,8 +52,11 @@ export default class RhsThread extends React.Component { PostStore.addSelectedPostChangeListener(this.onChange); PostStore.addChangeListener(this.onChangeAll); PreferenceStore.addChangeListener(this.forceUpdateInfo); + this.resize(); window.addEventListener('resize', this.handleResize); + + this.mounted = true; } componentDidUpdate() { if ($('.post-right__scroll')[0]) { @@ -63,7 +68,10 @@ export default class RhsThread extends React.Component { PostStore.removeSelectedPostChangeListener(this.onChange); PostStore.removeChangeListener(this.onChangeAll); PreferenceStore.removeChangeListener(this.forceUpdateInfo); + window.removeEventListener('resize', this.handleResize); + + this.mounted = false; } forceUpdateInfo() { if (this.state.postList) { @@ -82,7 +90,7 @@ export default class RhsThread extends React.Component { } onChange() { var newState = this.getStateFromStores(); - if (!Utils.areObjectsEqual(newState, this.state)) { + if (this.mounted && !Utils.areObjectsEqual(newState, this.state)) { this.setState(newState); } } @@ -120,7 +128,7 @@ export default class RhsThread extends React.Component { } var newState = this.getStateFromStores(); - if (!Utils.areObjectsEqual(newState, this.state)) { + if (this.mounted && !Utils.areObjectsEqual(newState, this.state)) { this.setState(newState); } } -- cgit v1.2.3-1-g7c22