[React] 현재 글자 수 체크, ChangeEvent

bunny.log·2022년 9월 30일
0
post-custom-banner
function InputAreaType(props: IInputAreaProps): JSX.Element {
	const { title, require, registerName, topLine, limit } = props;
	const [txtLength, setTxtLength] = useState(0);

	const onChangeHandler = useCallback((e: ChangeEvent<HTMLTextAreaElement>) => {
		setTxtLength(e.target.value.length);
	}, []);

	return (
		<Container topLine={topLine || false} require={require || false}>
			<div className="title">
				{title}
				<span className="require">&nbsp;*</span>
			</div>
			<div className="input-text">
				<textarea
					id="eventInfo"
					maxLength={limit}
					onChange={onChangeHandler}
				/>
				<div className="letter-num">
					<span className="current">{txtLength}</span> / 2000
				</div>
			</div>
		</Container>
	);
}
profile
https://github.com/nam-yeun-hwa
post-custom-banner

0개의 댓글