Skip to content

Instantly share code, notes, and snippets.

@souporserious
Created October 15, 2019 22:07
Show Gist options
  • Save souporserious/fec05d33170338a04b444245a7cb18e3 to your computer and use it in GitHub Desktop.
Save souporserious/fec05d33170338a04b444245a7cb18e3 to your computer and use it in GitHub Desktop.
export function useZoom({ onZoom }) {
useEffect(() => {
let lastRatio = window.devicePixelRatio
function checkZooming(event) {
if (lastRatio !== window.devicePixelRatio) {
if (onZoom) {
onZoom(event)
}
lastRatio = window.devicePixelRatio
}
}
window.addEventListener('resize', checkZooming)
return () => {
window.removeEventListener('resize', checkZooming)
}
}, [onZoom])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment