Skip to content

Commit

Permalink
fix: ensure field debounce doesn't sporadically lock preview update
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Nov 12, 2023
1 parent 2e931bc commit 932e412
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/core/components/InputOrGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TextareaField,
} from "./fields";
import { Lock } from "react-feather";
import { useDebouncedCallback, useDebounce } from "use-debounce";
import { useDebouncedCallback } from "use-debounce";

const getClassName = getClassNameFactory("Input", styles);

Expand Down Expand Up @@ -91,17 +91,17 @@ export const InputOrGroup = ({ onChange, ...props }: InputProps) => {

const [localValue, setLocalValue] = useState(value);

const [localValueDb] = useDebounce(localValue, 50, { leading: true });

useEffect(() => {
// Compare initial value to prevent calling on render
if (value !== localValueDb) {
onChange(localValueDb);
}
}, [localValueDb]);
const onChangeDb = useDebouncedCallback(
(val) => {
onChange(val);
},
50,
{ leading: true }
);

const onChangeLocal = useCallback((val) => {
setLocalValue(val);
onChangeDb(val);
}, []);

useEffect(() => {
Expand Down

0 comments on commit 932e412

Please sign in to comment.