Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

rationale for useWindowResize

Oleg Isonenf313c70d877c
diff --git a/app/shared/dom-hooks/use-window-resize.ts b/app/shared/dom-hooks/use-window-resize.ts
index 29302d904c..8c07e4a445 100644
--- a/app/shared/dom-hooks/use-window-resize.ts
+++ b/app/shared/dom-hooks/use-window-resize.ts
@@ -13,6 +13,11 @@ if (typeof window === "object") {
);
}
+/**
+ * Subscribe to DOM resize event only once and then notify all listeners over js only.
+ * This allows us to subscribe to resize by many listeners without perf issues, since its going to be the same resize event.
+ * TODO: We can add throttling and RAF if needed.
+ */
export const useWindowResize = (onResize: () => void) => {
useEffect(() => {
emitter.on("resize", onResize);