react-hook-form#ErrorMessage TypeScript Examples
The following examples show how to use
react-hook-form#ErrorMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Input.tsx From convoychat with GNU General Public License v3.0 | 5 votes |
Input: React.FC<InputProps> = ({
label,
inputRef,
errors,
icon: Icon,
postfixIcon: PostFixIcon,
onPostfixIconClick,
...props
}) => {
let _inputRef = useRef<HTMLInputElement>();
let hasErrors = errors && errors[props.name];
return (
<InputWrapper className="form--input__wrapper">
<StyledLabel hasErrors={hasErrors}>
{label && <span>{label}</span>}
<Flex align="center" className={!!Icon ? "input__wrapper" : ""}>
{Icon && <Icon data-testid="input-icon" className="input__icon" />}
<StyledInput
ref={e => {
_inputRef.current = e;
inputRef && inputRef(e);
}}
{...props}
aria-label={props.name}
/>
{PostFixIcon && (
<PostFixIcon
onClick={() => onPostfixIconClick(_inputRef?.current)}
data-testid="input-postfix-icon"
className="input__icon postfix-icon"
/>
)}
</Flex>
</StyledLabel>
{errors && (
<div
data-testid="input-error"
className={`text--error ${hasErrors && "show-error"}`}
>
<ErrorMessage errors={errors} name={props.name} />
</div>
)}
</InputWrapper>
);
}