import { FunctionComponent, ReactElement } from "react"; import { styled } from "@mui/joy"; import lodash from "lodash"; import { useFormikContext } from "formik"; export interface ITextFieldProps { name: string; help?: string; [key: string]: any; } const Root = styled("div")``; const TextField: FunctionComponent = ( props: ITextFieldProps ): ReactElement => { const { label, name, help, required, ...otherProps } = props; const formik = useFormikContext(); const error = lodash.get(formik.touched, name) && lodash.get(formik.errors, name); return (
{label && ( )}
{error && {error}} {!error && help}
); }; export default TextField;