{"id":333993,"date":"2022-06-02T21:00:23","date_gmt":"2022-06-02T21:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=333993"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=333993","title":{"rendered":"<span>\u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e react-redux-hook-form<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u042d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0438 \u0432 \u043d\u0435\u0439 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e, \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043d\u043e\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438. \u041d\u043e \u0441\u043f\u0435\u0440\u0432\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438.<\/p>\n<ol>\n<li>\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0431\u0443\u0434\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u043e\u0440\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u0438, \u0435\u0449\u0435 \u043f\u0440\u043e\u0449\u0435, \u043e\u0431\u043b\u0430\u0433\u0430\u0442\u044c \u0438\u0445 \u0442\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u043d\u0430\u044f \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0438\u043d\u043f\u0443\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u043d\u043f\u0443\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0435\u044e\u0437\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u0438 \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u043e\u0440\u043c\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e react-redux-hook-form.<\/p>\n<pre><code class=\"javascript\">export const Login:FC = memo( () => {   const form = useForm({name: 'login'})    return (     &lt;WrapperForm form={form} onSubmit={(data:ILogin) => {User.options.login(data)}}>       &lt;InputTitleStyled>\u041d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430&lt;\/InputTitleStyled>       &lt;PhoneInput name={'username'} required\/>        &lt;InputTitleStyled>\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/InputTitleStyled>       &lt;PasswordInput name={'password'} required\/>        &lt;SubmitButton text={'\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f'}\/>     &lt;\/WrapperForm>   ) })<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0443\u043a useForm \u0438 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b WrapperForm. <\/p>\n<p>useForm &#8212; \u0445\u0443\u043a \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 name \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u043e\u0439. form.reset, form.changeDataField, form.changeIsValidateField, form.changeMessageErrorField, form.useFieldSelector. \u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>WrapperForm &#8212; \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u0444\u043e\u0440\u043c\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u0430 \u0444\u043e\u0440\u043c\u0430. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: onChange, initialValue, onSubmit.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u043f\u0443\u0442\u044b.<\/p>\n<pre><code class=\"javascript\">interface IEmail {   name: string;   required?: boolean; }  export const EmailInput: FC&lt;IEmail> = (props) => {   const {useData, useIsValidate, useIsTouch, useMessageError} = useField({     name: props.name,     isRequired: props.required,     validateFunction: (value:string) => validate(value).string().max(30).email(),   })    const [data, changeData] = useData()   const [isValidate, ] = useIsValidate()   const [isTouch, ] = useIsTouch()   const [messageError, ] = useMessageError()    return (     &lt;>       &lt;EmailInputStyled         type={\"email\"}  value={data}         onChange={(e:any)=> {changeData(e.target.value)}}         isValidate={isValidate || !isTouch}         id={props.name}       \/>       {!isValidate &amp;&amp; isTouch &amp;&amp;         &lt;ErrorTitleStyled className={'error'}>           {messageError}         &lt;\/ErrorTitleStyled>       }     &lt;\/>   ) };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c useField. useField &#8212; \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 \u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0445\u0443\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u043b\u0435\u043c. useData, useIsValidate, useIsTouch, useMessageError, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 useState. Validate\/IsTouch\/MessageError &#8212; \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 useField \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c isDisableAuto: true.<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b useField: name, initialValue, isRequired, isDisableAuto, messageError, isTouch, isValidate, validateFunction.<\/p>\n<p>name: \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f. \u0412\u0441\u0435 \u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<p>initialValue: \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0421\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0438\u043d\u043f\u0443\u0442\u0435. \u041f\u0435\u0440\u0435\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f initialValues \u0441 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443, \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<pre><code class=\"javascript\">interface ISubmitButton {   text: string;   className?: string; }  export const SubmitButton: FC&lt;ISubmitButton> = (props) => {   const formName = useContext(formNameContext)   const isValidForm = useIsValidForm(formName)   const onSubmit = useContext(onSubmitContext)    const onClick = () => {     if(isValidForm){       onSubmitForm(formName, onSubmit)     }   }   return (     &lt;SubmitButtonStyled className={props.className} isValidForm={isValidForm} onClick={onClick}>       {props.text}     &lt;\/SubmitButtonStyled>   ) };<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 formName \u0438 onSubmit.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c useIsValidateForm \u0445\u0443\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u043c\u044f \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>\u0422\u0430\u043a-\u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c redux. \u0422\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">const search = useFieldSelector({formName: 'searchForm', fieldName: 'search'})<\/code><\/pre>\n<p><strong>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 react-redux-hook-form.<\/strong><\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c: npm i\u00a0react-redux-hook-form.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430\u0434\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u0440.<\/p>\n<p>1) \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c formControllerReducer.<\/p>\n<pre><code class=\"javascript\">import { formControllerReducer } from 'react-redux-hook-form';  const combinedReducer = combineReducers({   formController: formControllerReducer, \/\/ \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 formControllerReducer   user: userReducer,   contact: contactReducer, });<\/code><\/pre>\n<p>2) \u0417\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<code>getState<\/code>\u00a0\u0432 window.<\/p>\n<pre><code class=\"javascript\">window.getState = () => store.getState()<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u044d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c react-redux-hook-form.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c redux, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0447\u0435\u0440\u0435\u0437 redux-devtools(\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0433\u0443\u0433\u043b \u0445\u0440\u043e\u043c\u0430).<\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u0435\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u0441\u0435\u0431\u0435. \u0423 \u043c\u0435\u043d\u044f \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c 1.5 \u0433\u043e\u0434\u0430. \u0434\u0430 \u0438 \u0442\u043e \u0442\u0440\u0435\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430 \u0431\u044d\u043a\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043f\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \ud83d\ude42<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/669362\/\"> https:\/\/habr.com\/ru\/post\/669362\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u042d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0438 \u0432 \u043d\u0435\u0439 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e, \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043d\u043e\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438. \u041d\u043e \u0441\u043f\u0435\u0440\u0432\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438.<\/p>\n<ol>\n<li>\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0431\u0443\u0434\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u043e\u0440\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u0438, \u0435\u0449\u0435 \u043f\u0440\u043e\u0449\u0435, \u043e\u0431\u043b\u0430\u0433\u0430\u0442\u044c \u0438\u0445 \u0442\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u043d\u0430\u044f \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0438\u043d\u043f\u0443\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u043d\u043f\u0443\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0435\u044e\u0437\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u0438 \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u043e\u0440\u043c\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e react-redux-hook-form.<\/p>\n<pre><code class=\"javascript\">export const Login:FC = memo( () => {   const form = useForm({name: 'login'})    return (     &lt;WrapperForm form={form} onSubmit={(data:ILogin) => {User.options.login(data)}}>       &lt;InputTitleStyled>\u041d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430&lt;\/InputTitleStyled>       &lt;PhoneInput name={'username'} required\/>        &lt;InputTitleStyled>\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/InputTitleStyled>       &lt;PasswordInput name={'password'} required\/>        &lt;SubmitButton text={'\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f'}\/>     &lt;\/WrapperForm>   ) })<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0443\u043a useForm \u0438 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b WrapperForm. <\/p>\n<p>useForm &#8212; \u0445\u0443\u043a \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 name \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u043e\u0439. form.reset, form.changeDataField, form.changeIsValidateField, form.changeMessageErrorField, form.useFieldSelector. \u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>WrapperForm &#8212; \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u0444\u043e\u0440\u043c\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u0430 \u0444\u043e\u0440\u043c\u0430. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: onChange, initialValue, onSubmit.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u043f\u0443\u0442\u044b.<\/p>\n<pre><code class=\"javascript\">interface IEmail {   name: string;   required?: boolean; }  export const EmailInput: FC&lt;IEmail> = (props) => {   const {useData, useIsValidate, useIsTouch, useMessageError} = useField({     name: props.name,     isRequired: props.required,     validateFunction: (value:string) => validate(value).string().max(30).email(),   })    const [data, changeData] = useData()   const [isValidate, ] = useIsValidate()   const [isTouch, ] = useIsTouch()   const [messageError, ] = useMessageError()    return (     &lt;>       &lt;EmailInputStyled         type={\"email\"}  value={data}         onChange={(e:any)=> {changeData(e.target.value)}}         isValidate={isValidate || !isTouch}         id={props.name}       \/>       {!isValidate &amp;&amp; isTouch &amp;&amp;         &lt;ErrorTitleStyled className={'error'}>           {messageError}         &lt;\/ErrorTitleStyled>       }     &lt;\/>   ) };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c useField. useField &#8212; \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 \u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0445\u0443\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u043b\u0435\u043c. useData, useIsValidate, useIsTouch, useMessageError, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 useState. Validate\/IsTouch\/MessageError &#8212; \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 useField \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c isDisableAuto: true.<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b useField: name, initialValue, isRequired, isDisableAuto, messageError, isTouch, isValidate, validateFunction.<\/p>\n<p>name: \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f. \u0412\u0441\u0435 \u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<p>initialValue: \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0421\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0438\u043d\u043f\u0443\u0442\u0435. \u041f\u0435\u0440\u0435\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f initialValues \u0441 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443, \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<pre><code class=\"javascript\">interface ISubmitButton {   text: string;   className?: string; }  export const SubmitButton: FC&lt;ISubmitButton> = (props) => {   const formName = useContext(formNameContext)   const isValidForm = useIsValidForm(formName)   const onSubmit = useContext(onSubmitContext)    const onClick = () => {     if(isValidForm){       onSubmitForm(formName, onSubmit)     }   }   return (     &lt;SubmitButtonStyled className={props.className} isValidForm={isValidForm} onClick={onClick}>       {props.text}     &lt;\/SubmitButtonStyled>   ) };<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 formName \u0438 onSubmit.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c useIsValidateForm \u0445\u0443\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u043c\u044f \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>\u0422\u0430\u043a-\u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c redux. \u0422\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">const search = useFieldSelector({formName: 'searchForm', fieldName: 'search'})<\/code><\/pre>\n<p><strong>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 react-redux-hook-form.<\/strong><\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c: npm i\u00a0react-redux-hook-form.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430\u0434\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u0440.<\/p>\n<p>1) \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c formControllerReducer.<\/p>\n<pre><code class=\"javascript\">import { formControllerReducer } from 'react-redux-hook-form';  const combinedReducer = combineReducers({   formController: formControllerReducer, \/\/ \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 formControllerReducer   user: userReducer,   contact: contactReducer, });<\/code><\/pre>\n<p>2) \u0417\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<code>getState<\/code>\u00a0\u0432 window.<\/p>\n<pre><code class=\"javascript\">window.getState = () => store.getState()<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u044d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c react-redux-hook-form.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c redux, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0447\u0435\u0440\u0435\u0437 redux-devtools(\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0433\u0443\u0433\u043b \u0445\u0440\u043e\u043c\u0430).<\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u0435\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u0441\u0435\u0431\u0435. \u0423 \u043c\u0435\u043d\u044f \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c 1.5 \u0433\u043e\u0434\u0430. \u0434\u0430 \u0438 \u0442\u043e \u0442\u0440\u0435\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430 \u0431\u044d\u043a\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043f\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \ud83d\ude42<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/669362\/\"> https:\/\/habr.com\/ru\/post\/669362\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-333993","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333993"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333993\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}