Skip to content

Commit

Permalink
(#0) useValueChangeEffect Error
Browse files Browse the repository at this point in the history
  • Loading branch information
baegofda committed Dec 3, 2023
1 parent 852a9d6 commit 46037d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/core/components/Input/InputTextArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const InputTextArea = forwardRef((

onChangeHandler(e);
};

return (
<InputBase
label = {label}
Expand Down
13 changes: 10 additions & 3 deletions src/core/components/Input/hooks/effects/useValueChangeEffect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Dispatch, SetStateAction, useEffect } from "react";
import { Dispatch, SetStateAction, useEffect, useRef } from "react";
import { UseInputProps } from "../useInput";

const useValueChangeEffect = (value: UseInputProps["value"], setInputValue: Dispatch<SetStateAction<UseInputProps["value"]>>) => {
const isFirst = useRef(true);

useEffect(() => {
setInputValue(value);
}, [ value, setInputValue ]);
if (!isFirst.current) {
return setInputValue(value);
}

isFirst.current = false;
}, [ value, setInputValue, isFirst.current ]);
};

export default useValueChangeEffect;

0 comments on commit 46037d6

Please sign in to comment.