import { useEffect, useState } from 'react'; import { Form, FormGroup, FormHelperText, TextInput, HelperText, HelperTextItem } from '@patternfly/react-core'; export const HelperTextDynamic: React.FunctionComponent = () => { const [value, setValue] = useState(''); const [inputValidation, setInputValidation] = useState('default'); const handleInputChange = (_event, inputValue: string) => { setValue(inputValue); }; useEffect(() => { if (value === '') { setInputValidation('default'); } else if (value === 'johndoe') { setInputValidation('error'); } else { setInputValidation('success'); } }, [value]); return (
{inputValidation !== 'success' && ( {inputValidation === 'default' ? 'Please enter a username' : 'Username already exists'} )}
); };