Answer the question
In order to leave comments, you need to log in
How to make react-hook-form work?
there is a component that returns a styled TextField from react-material ui
...
return (
<>
<TextField
name={name}
label={label}
type={type === 'password' ? showPassword ? 'text' : 'password' : type}
variant="filled"
onChange={onChange}
InputProps={inputProps}
InputLabelProps={{
classes: {
root: classes.vp_label,
}
}}
classes={{
root: classes.vp_root
}}
inputRef={register({ required: true })}
/>
</>
)
import React, { useState, useContext } from 'react';
import Field from '../../UI/TextField/Field';
import { useForm } from 'react-hook-form'
const LoginForm = () => {
const classes = useStyles();
const { register, handleSubmit, errors } = useForm();
const [state, setState] = useState({
email: '',
password: '',
rememberMe: false
});
const changeHandler = (event) => {
setState({
...state,
[event.target.name]: event.target.value
})
};
const onSubmitHandler = (data) => {
console.log(data)
console.log(errors)
};
return (
<form onSubmit={ handleSubmit(onSubmitHandler) }>
<h3 className={classes.formHeading}>Авторизация</h3>
<div className={classes.mb8}>
<Field
type={'email'}
label={'Эл. почта'}
name={'email'}
onChange={changeHandler}
register={register}
/>
</div>
<Button
variant="contained"
className={classes.buttonEnter}
disableElevation
onClick={onSubmitHandler}
>
Войти
</Button>
</form>
)
};
Answer the question
In order to leave comments, you need to log in
The dock has an example of how to integrate with ui libs https://react-hook-form.com/get-started#Integratin...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question