textarea
๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ณธ์ธ์ ๋์ด๋ณด๋ค ๋ ๋ง์ ์ปจํ ์ธ ๋ฅผ ๋ฃ์ผ๋ฉด ์คํฌ๋กค๋ฐ๊ฐ ์์ฑ๋๊ฒ ๋ฉ๋๋ค.
์ด๋ฒ์ ๊ตฌํํ๋ ๊ฒ์ ๋ฌธ์์ ๋ฐ๋ผ์ ๋์ด๊ฐ ์๋์ผ๋ก ์ค์ด๋ค๊ณ ๋์ด๋๋ ๊ฒ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๊ธฐ๋กํ๋ ค๊ณ ํฉ๋๋ค.
react-hook-form
๊ณผ ๋ณํฉํด์ ์ฒ๋ฆฌํ๊ธฐ ๋๋ฌธ์ ์ถ๊ฐ์ ์ธ ์ฝ๋๊ฐ ์กฐ๊ธ ๋ ์์ต๋๋ค.
// 2022/04/30 - comment Ref - by 1-blue
const { ref, ...rest } = register("comment");
const commentRef = useRef<HTMLTextAreaElement | null>(null);
// 2022/04/30 - textarea ์๋ ๋์ด ์กฐ์ - by 1-blue
const handleResizeHeight = useCallback(() => {
if (!commentRef.current) return;
commentRef.current.style.height = "auto";
commentRef.current.style.height = commentRef.current?.scrollHeight + "px";
}, [commentRef]);
// jsx
<textarea
placeholder="๋๊ธ์ ์์ฑํ์ธ์"
{...rest}
className="w-full p-4 focus:outline-none resize-none rounded-sm bg-zinc-200 dark:bg-zinc-600"
onInput={handleResizeHeight}
ref={(e) => {
ref(e);
commentRef.current = e;
}}
/>
Pinterest is a great source chick fil a breakfast hours of inspiration for DIY projects.