From 7894033031bb02672b08f6b8ada1f67be4d4181b Mon Sep 17 00:00:00 2001 From: Jannick Garthen Date: Sun, 16 Feb 2020 13:12:04 +0100 Subject: [PATCH] fix(ObserveViewport): ensure that children are always updated with the most recent values This fixes an issue where the component receives an empty viewport object by default. --- lib/ObserveViewport.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ObserveViewport.tsx b/lib/ObserveViewport.tsx index b191b6e..5bc0aef 100644 --- a/lib/ObserveViewport.tsx +++ b/lib/ObserveViewport.tsx @@ -58,6 +58,7 @@ export default class ObserveViewport extends React.Component { ) => void; private tickId?: number; + private nextViewport?: IViewport; static defaultProps: IProps = { disableScrollUpdates: false, @@ -109,11 +110,15 @@ export default class ObserveViewport extends React.Component { } }; - 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; }); } }