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.

debounce breakpoint change

Oleg Isonen86cf09fc6052
diff --git a/app/designer/features/topbar/breakpoints.tsx b/app/designer/features/topbar/breakpoints.tsx
index 60f131d09c..f7426dbabd 100644
--- a/app/designer/features/topbar/breakpoints.tsx
+++ b/app/designer/features/topbar/breakpoints.tsx
@@ -1,4 +1,5 @@
import { useState } from "react";
+import useDebounce from "react-use/lib/useDebounce";
import { type Breakpoint } from "@webstudio-is/sdk";
import {
DropdownMenu,
@@ -27,10 +28,22 @@ type EditableBreakpointProps = {
};
const EditableBreakpoint = ({
- breakpoint,
+ breakpoint: initialBreakpoint,
onChange,
onFocus,
}: EditableBreakpointProps) => {
+ const [breakpoint, setBreakpoint] = useState(initialBreakpoint);
+
+ useDebounce(
+ () => {
+ if (breakpoint !== initialBreakpoint) {
+ onChange(breakpoint);
+ }
+ },
+ 1000,
+ [breakpoint]
+ );
+
return (
<form
onKeyDown={(event) => {
@@ -45,7 +58,7 @@ const EditableBreakpoint = ({
label: String(data.get("label")),
minWidth: Number(data.get("minWidth")),
};
- onChange(nextBreakpoint);
+ setBreakpoint(nextBreakpoint);
}}
onFocus={onFocus}
>