Skip to content

Commit

Permalink
fix(ObserveViewport): ensure that children are always updated with th…
Browse files Browse the repository at this point in the history
…e most recent values

This fixes an issue where the component receives an empty viewport
object by default.
  • Loading branch information
garthenweb committed Feb 16, 2020
1 parent 09a0bfb commit 7894033
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ObserveViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default class ObserveViewport extends React.Component<IProps, IState> {
) => void;

private tickId?: number;
private nextViewport?: IViewport;

static defaultProps: IProps = {
disableScrollUpdates: false,
Expand Down Expand Up @@ -109,11 +110,15 @@ export default class ObserveViewport extends React.Component<IProps, IState> {
}
};

syncState(nextViewport: IState) {
syncState(nextViewport: IViewport) {
this.nextViewport = nextViewport;
if (this.tickId === undefined) {
this.tickId = requestAnimationFrame(() => {
this.setState(nextViewport);
if (this.nextViewport) {
this.setState(this.nextViewport);
}
this.tickId = undefined;
this.nextViewport = undefined;
});
}
}
Expand Down

0 comments on commit 7894033

Please sign in to comment.