1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-26 00:35:02 +03:00

Adjust storage focus state

This commit is contained in:
Brent Jackson 2019-04-20 19:24:48 -04:00
parent 2259a9d270
commit 565929e0ae

View File

@ -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)