fix up tweet button

main
Mike Fix 6 years ago
parent d1cf2cea5c
commit 25828af37f

@ -10,17 +10,27 @@ function useWindowListener(key, fn) {
}, [])
}
function TweetButton(props) {
function useOnlineListener() {
const [online, setOnline] = React.useState(true)
const [onClick, { loading }] = useAsyncCallback(props.onClick)
React.useEffect(() => {
setOnline(Boolean(window && window.navigator && window.navigator.onLine))
setOnline(
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean'
? navigator.onLine
: true
)
}, [])
useWindowListener('offline', () => setOnline(false))
useWindowListener('online', () => setOnline(true))
return online
}
function TweetButton(props) {
const online = useOnlineListener()
const [onClick, { loading }] = useAsyncCallback(props.onClick)
if (!online) {
return null
}

Loading…
Cancel
Save