Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Created July 17, 2021 18:03
Show Gist options
  • Save DZuz14/fc383608529a14220bd6bd028b6b0366 to your computer and use it in GitHub Desktop.
Save DZuz14/fc383608529a14220bd6bd028b6b0366 to your computer and use it in GitHub Desktop.
const SomeComponent = () => {
const { fields, success, errors, handleSubmit, setFields } =
useFormValidationHook(formData)
return (
<div className="Form" css={CSS}>
<Form onSubmit={handleSubmit}>
{fields.map((field) => (
<FormGroup key={field.name}>
<Form.Label>{field.name}</Form.Label>
<Form.Control
className={errors[field.name] ? 'outline-error' : ''}
type={field.type}
as={field.type === 'textarea' ? 'textarea' : 'input'}
name={field.name}
value={field.value}
onChange={setFields}
placeholder={field.placeholder}
/>
<div className="error-message">{errors[field.name] || ''}</div>
</FormGroup>
))}
<p className="success">{success}</p>
<div className="submit-button">
<Button variant="info" type="submit">
Submit
</Button>
</div>
</Form>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment