I'm sorry if I duplicate the question but I didn't find any solution for my problem.
What is the best way in React to detect switching tabs in browser or hide browser window?
I know there is a Page visibility API for it but how can I implement it in React component?
Here is the easiest way but I don't know is correct
import React, { Component } from 'react';
class Sample extends Component {
handleBlur = () => {
console.log('Blur');
}
handleFocus = () => {
console.log('Focus');
}
render() {
return (
<div
style={{ width: 400, height: 200 }}
onBlur={this.handleBlur}
onFocus={this.handleFocus}
>
test
</div>
);
}
}
export default Sample;