function App () {
const [isMobile, setIsMobile] = React.useState(false)
React.useEffect(() => {
window.addEventListener('resize', handleResize, true);
return () => {
window.removeEventListener('resize', handleResize, true);
}
}, [])
const handleResize = React.useCallback((event) => {
// you can use window's width to recognize a mobile device width
// you can also use its height to see whether the mode is landscape or portrait
const width = event.currentTarget.innerWidth
console.log('Window width:', width)
setIsMobile(width <= 1024)
}, [])
return (
<React.Fragment>
Resize me to see a console log!
</React.Fragment>
)
}