From 8591f48ed22e5e7275b8f27e843d7806eb721559 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Fri, 31 May 2019 13:59:28 +0800 Subject: [PATCH] Add SSR support resolved #6 --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 32509f1..c89b6a0 100644 --- a/index.js +++ b/index.js @@ -13,10 +13,15 @@ try { window.removeEventListener('testPassive', null, opts) } catch (e) {} -let getPosition = () => ({ - x: window.pageXOffset, - y: window.pageYOffset, -}) +let getPosition = () => { + if (typeof window === 'undefined') { + return { x: 0, y: 0 }; + } + return { + x: window.pageXOffset, + y: window.pageYOffset, + }; +}; let defaultOptions = { throttle: 100,