Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save full-stack-concepts/51f2df63c064c4b9d3135c72c6d64738 to your computer and use it in GitHub Desktop.
Save full-stack-concepts/51f2df63c064c4b9d3135c72c6d64738 to your computer and use it in GitHub Desktop.
import React from 'react';
import { Controller } from 'react-hook-form';
import TextField from '@mui/material/TextField';
function defaultTextField({
fieldName,
fieldType,
control,
register,
label,
required,
onChangeHandler,
onBlurHandler
}) {
const type = (fieldType) ? fieldType : 'text';
return(
<Controller
name={fieldName}
control={control}
defaultValue=""
render={({ field: { value, name, ref }, fieldState: { error } }) => (
<TextField
{...register( fieldName, {
onChange: e => onChangeHandler(e, fieldName),
onBlur: e => onBlurHandler(e, fieldName)
})}
id={fieldName}
label={label}
type={type}
variant="outlined"
value={value}
error={!!error}
helperText={error ? error.message : null}
margin="normal"
fullWidth
required={required}
/>
)}
/>)
}
export default defaultTextField;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment