import React, { useEffect, useState } from 'react' import classNames from 'classnames' import styles from './index.module.scss' interface Props extends React.DetailedHTMLProps< React.InputHTMLAttributes, HTMLInputElement > { bound?: boolean visible?: string error?: string label?: string } const defaultProps = { visible: 'true', } const Input = React.forwardRef(function Input( { value, visible, bound, error, label, ...props }: Props, forwardedRef ) { // States const [inputValue, setInputValue] = useState('') // Classes const classes = classNames( { [styles.input]: true, [styles.bound]: bound, }, props.className ) const { defaultValue, ...inputProps } = props // Change value when prop updates useEffect(() => { if (value) setInputValue(`${value}`) }, [value]) function handleChange(event: React.ChangeEvent) { setInputValue(event.target.value) if (props.onChange) props.onChange(event) } return ( {error && error.length > 0 &&

{error}

}
) }) Input.defaultProps = defaultProps export default Input