diff --git a/src/components/node/Tags/index.tsx b/src/components/node/Tags/index.tsx index cf2bcdb8..09469ac2 100644 --- a/src/components/node/Tags/index.tsx +++ b/src/components/node/Tags/index.tsx @@ -35,7 +35,9 @@ export const Tags: FC = ({ tags, is_editable, onTagsChange, ...props }) const onInput = useCallback( ({ target: { value } }: ChangeEvent) => { setInput(value); - if (timer) clearTimeout(timer.current); + if (timer) { + clearTimeout(timer.current); + } }, [setInput, timer] ); @@ -69,8 +71,10 @@ export const Tags: FC = ({ tags, is_editable, onTagsChange, ...props }) const onSubmit = useCallback(() => { if (length(tags) === length(data) && isEmpty(symmetricDifference(tags, data))) return; + if (timer.current) clearTimeout(timer.current); + onTagsChange(data.map(tag => tag.title)); - }, [tags, data, onTagsChange]); + }, [tags, data, onTagsChange, timer]); const onBlur = useCallback(() => { clearTimeout(timer.current); @@ -79,10 +83,14 @@ export const Tags: FC = ({ tags, is_editable, onTagsChange, ...props }) useEffect(() => setData(tags), [tags]); useEffect(() => { - timer.current = setTimeout(onSubmit, 3000); + timer.current = setTimeout(() => { + onSubmit(); + }, 3000); - return () => clearTimeout(timer.current); - }, [data]); + return () => { + clearTimeout(timer.current); + }; + }, [data, tags]); return (