Skip to content

Instantly share code, notes, and snippets.

@sagarPakhrin
Created March 5, 2021 08:56
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 sagarPakhrin/0ebf177473355663611edfa1d48e81cd to your computer and use it in GitHub Desktop.
Save sagarPakhrin/0ebf177473355663611edfa1d48e81cd to your computer and use it in GitHub Desktop.
Formik Custom Input
import React from "react";
import { useField } from "formik";
const CustomInput = ({ label, ...props }) => {
const [field, meta] = useField(props);
return (
<div className="flex flex-col text-left">
{label && <label htmlFor={props.id || props.name}>{label}</label>}
<input
{...field}
{...props}
className="border-b border-primary focus:outline-none focus:border-blue-500"
/>
{meta.touched && meta.error ? (
<div className="text-red-500 text-sm">{meta.error}</div>
) : null}
</div>
);
};
export default CustomInput;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment