Skip to content

Instantly share code, notes, and snippets.

@scottsauber
Last active January 1, 2022 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsauber/ca4d1dacc5f726a2154e6775ef7d74fa to your computer and use it in GitHub Desktop.
Save scottsauber/ca4d1dacc5f726a2154e6775ef7d74fa to your computer and use it in GitHub Desktop.
import React from "react";
import { Field } from "formik";
const InputField = (props) => {
return (
<Field name={props.fieldName}>
{({ field, form }) => (
<div>
<label htmlFor={props.fieldName}>{props.labelName}</label>
<input {...field} id={props.fieldName} type="text" />
{form.errors[props.fieldName] && form.touched[props.fieldName] ? (
<div data-testid={`errors-${props.fieldName}`}>
{form.errors[props.fieldName]}
</div>
) : null}
</div>
)}
</Field>
);
};
export default InputField;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment