Created
March 5, 2021 08:56
-
-
Save sagarPakhrin/0ebf177473355663611edfa1d48e81cd to your computer and use it in GitHub Desktop.
Formik Custom Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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