Skip to content

Commit

Permalink
fix(ObserveViewport): don't waist time with rerender if nothing will …
Browse files Browse the repository at this point in the history
…be rendered anyhow
  • Loading branch information
garthenweb committed Oct 27, 2018
1 parent 9853706 commit d0ca819
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/ObserveViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export default class ObserveViewport extends React.Component<IProps, IState> {
};
}

shouldComponentUpdate(nextProps: IProps) {
return Boolean(nextProps.children);
}

componentWillUnmount() {
if (this.removeViewportChangeListener) {
this.removeViewportChangeListener(this.handleViewportUpdate);
Expand All @@ -95,9 +91,11 @@ export default class ObserveViewport extends React.Component<IProps, IState> {
this.props.onUpdate(nextViewport, layoutSnapshot);
}

this.tickId = raf(() => {
this.setState(nextViewport);
});
if (this.props.children) {
this.tickId = raf(() => {
this.setState(nextViewport);
});
}
};

get optionNotifyScroll(): boolean {
Expand Down

0 comments on commit d0ca819

Please sign in to comment.