Skip to content

Commit

Permalink
Remove useEffect from InputTextArea
Browse files Browse the repository at this point in the history
  • Loading branch information
charlielee committed Nov 27, 2023
1 parent 207560f commit 2f4d96c
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from "react";
import { useCallback } from "react";

interface InputTextAreaProps {
id?: string;
Expand All @@ -19,13 +19,14 @@ const InputTextArea = ({
disabled = false,
autoScroll = false,
}: InputTextAreaProps): JSX.Element => {
const textAreaRef = useRef<HTMLTextAreaElement>(null);

useEffect(() => {
if (autoScroll && textAreaRef.current) {
textAreaRef.current.scrollTop = textAreaRef.current.scrollHeight;
}
}, [autoScroll, value]);
const textAreaRef = useCallback(
(textArea: HTMLTextAreaElement | null) => {
if (textArea && autoScroll) {
textArea.scrollTop = textArea.scrollHeight;
}
},
[autoScroll, value] // eslint-disable-line react-hooks/exhaustive-deps
);

const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) =>
onChange(event.target.value);
Expand Down

0 comments on commit 2f4d96c

Please sign in to comment.