Skip to content
Snippets Groups Projects

Working email validation and hiding controller logic to InputField

Merged Defendi Alberto requested to merge api-login into dev
7 files
+ 61
57
Compare changes
  • Side-by-side
  • Inline
Files
7
import React, { FC } from 'react';
import React, { FC } from 'react';
import { TextField } from '@material-ui/core';
import { TextField } from '@material-ui/core';
 
import { Control, Controller, FieldValues } from 'react-hook-form';
type Props = {
type Props = {
id: string;
/**
 
* Name of the elemement. ex. email, password
 
*/
 
name: string;
label: string;
label: string;
error: boolean;
error: boolean;
errorMessage: string;
errorMessage: string;
value: string;
/**
onChange: any;
* react-hook-form control
 
*/
 
control: Control<FieldValues> | undefined;
 
rules: Partial<unknown>;
};
};
export const InputField: FC<Props> = (props: Props) => {
export const InputField: FC<Props> = (props: Props) => {
const { id, label, error, errorMessage, onChange, value } = props;
const { name, label, error, errorMessage, control, rules } = props;
return (
return (
<TextField
<Controller
variant="outlined"
name={name}
margin="normal"
control={control}
required
rules={rules}
fullWidth
render={({ onChange, value }) => (
id={id}
<TextField
label={label}
variant="outlined"
name={id}
margin="normal"
onChange={onChange}
required
value={value}
fullWidth
autoComplete={id}
id={name}
autoFocus
label={label}
error={error}
name={name}
helperText={error && errorMessage}
onChange={onChange}
 
value={value}
 
autoComplete={name}
 
autoFocus
 
error={error}
 
helperText={error && errorMessage}
 
/>
 
)}
/>
/>
);
);
};
};
Loading