From 565929e0ae344f96a3ee55ac0cca9fa3394e06d5 Mon Sep 17 00:00:00 2001 From: Brent Jackson Date: Sat, 20 Apr 2019 19:24:48 -0400 Subject: [PATCH] Adjust storage focus state --- packages/components/src/Storage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/components/src/Storage.js b/packages/components/src/Storage.js index a89f81a..f7a5d13 100644 --- a/packages/components/src/Storage.js +++ b/packages/components/src/Storage.js @@ -4,7 +4,7 @@ const STORAGE_INDEX = 'mdx-slide' const STORAGE_STEP = 'mdx-step' export const useLocalStorage = (handler, args = []) => { - const [focused, setFocused] = useState(true) + const [focused, setFocused] = useState(false) const handleFocus = () => { setFocused(true) } @@ -12,6 +12,7 @@ export const useLocalStorage = (handler, args = []) => { setFocused(false) } useEffect(() => { + setFocused(document.hasFocus()) if (!focused) window.addEventListener('storage', handler) window.addEventListener('focus', handleFocus) window.addEventListener('blur', handleBlur)