The current window dimensions are:
{"width":0,"height":0}
Get the size of your screen. At the moment just get the screen size at the first load, does not exists listener to get the screen on change the screen, but it is planned to the next iteration.
{"width":0,"height":0}
export function useScreen(): Partial<Screen> {
const getScreen = (): Partial<Screen> => {
if (typeof window !== "undefined" && window.screen) {
return window.screen;
}
return {
width: 0,
height: 0,
};
};
return getScreen();
}
<!-- javascript -->
<script lang="ts">
import { useScreen } from "@/hooks";
const screen = useScreen();
</script>
<!-- html -->
<div>
The current window dimensions are:
<code>
{JSON.stringify({ width: $screen?.width, height: $screen?.height })}
</code>
</div>