From 1e4c826a0a21441e91dde0a378bb902de09a6ab1 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Wed, 26 Nov 2025 01:27:00 +0700 Subject: [PATCH] fix(FE): fixing error missing component DebounceTextArea --- src/components/input/DebouncedTextArea.tsx | 44 +++++++++++++++++++ .../project-flock/form/ProjectFlockForm.tsx | 22 +++++++++- .../form/ProjectFlockKandangTable.tsx | 22 ++++++++-- 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 src/components/input/DebouncedTextArea.tsx diff --git a/src/components/input/DebouncedTextArea.tsx b/src/components/input/DebouncedTextArea.tsx new file mode 100644 index 00000000..3df2c032 --- /dev/null +++ b/src/components/input/DebouncedTextArea.tsx @@ -0,0 +1,44 @@ +'use client'; + +import { ChangeEvent, ChangeEventHandler, useEffect, useState } from 'react'; +import { useDebounce } from 'use-debounce'; + +import TextArea, { TextAreaProps } from '@/components/input/TextArea'; + +interface DebouncedTextAreaProps extends TextAreaProps { + delay?: number; +} + +const DebouncedTextArea = (props: DebouncedTextAreaProps) => { + const { delay, onChange } = props; + + const [internalChangeEvent, setInternalChangeEvent] = + useState>(); + const [internalValue, setInternalValue] = useState(props.value); + + const [debouncedChangeEvent] = useDebounce(internalChangeEvent, delay ?? 300); + const [debouncedValue] = useDebounce(internalValue, delay ?? 300); + + const internalChangeHandler: ChangeEventHandler = ( + e + ) => { + setInternalValue(e.target.value); + setInternalChangeEvent(e); + }; + + useEffect(() => { + if (debouncedChangeEvent) { + onChange?.(debouncedChangeEvent); + } + }, [debouncedValue]); + + return ( +