Created
May 17, 2019 22:32
-
-
Save davo/9058cdd4f690b4dbd29d450054d0fa5e to your computer and use it in GitHub Desktop.
Framer X WindowResizeListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://framer.slack.com/archives/CB74N2FDY/p1557954143213500?thread_ts=1557952502.211200&cid=CB74N2FDY | |
import { Override, Data } from "framer" | |
import * as React from "react" | |
const initialSize = document.body.getBoundingClientRect() | |
const preview = Data({ width: initialSize.width, height: initialSize.height }) | |
export function WindowResizeListener(): Override { | |
React.useEffect(function() { | |
function updateViewSize() { | |
const rect = document.body.getBoundingClientRect() | |
preview.width = rect.width | |
preview.height = rect.height | |
} | |
window.addEventListener("resize", updateViewSize) | |
return function removeListener() { | |
window.removeEventListener("resize", updateViewSize) | |
} | |
}) | |
return { | |
width: preview.width, | |
height: preview.height, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment