React Hook to show if window is focused or not
yarn add use-window-focus
import React from 'react';
import useWindowFocus from 'use-window-focus';
export default () => {
const windowFocused = useWindowFocus();
return (
<div>
<span>{windowFocused ? 'Focused' : 'Not focused'}</span>
</div>
);
}
The package is available as open source under the terms of the MIT License.