import React, { useEffect, useState } from "react"; import "./index.scss"; interface Props { fieldName: string; placeholder: string; value?: string; limit: number; error: string; onBlur?: (event: React.ChangeEvent) => void; onChange?: (event: React.ChangeEvent) => void; } const CharLimitedFieldset = React.forwardRef( function useFieldSet(props, ref) { const fieldType = ["password", "confirm_password"].includes(props.fieldName) ? "password" : "text"; const [currentCount, setCurrentCount] = useState(0); useEffect(() => { setCurrentCount( props.value ? props.limit - props.value.length : props.limit ); }, [props.limit, props.value]); function onChange(event: React.ChangeEvent) { setCurrentCount(props.limit - event.currentTarget.value.length); if (props.onChange) props.onChange(event); } return (
{currentCount}
{props.error.length > 0 &&

{props.error}

}
); } ); export default CharLimitedFieldset;