{"id":329966,"date":"2022-02-22T15:01:22","date_gmt":"2022-02-22T15:01:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=329966"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=329966","title":{"rendered":"<span>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 React \u0441\u043e 165 \u0434\u043e 30 \u0441\u0442\u0440\u043e\u043a<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041e\u0447\u0438\u0441\u0442\u043a\u0430 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e React Hook Form \u0438 Material UI  <\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8f9\/e49\/304\/8f9e493043c46ee651211d0c47dad2f6.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f9\/e49\/304\/8f9e493043c46ee651211d0c47dad2f6.png\"\/><figcaption><\/figcaption><\/figure>\n<p>React Hook Form \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b \u0432 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 React.<\/p>\n<p>\u041d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c React Hook Form \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 Material UI.<\/p>\n<h3>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>react-hook-form<\/code>. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>react-hook-form<\/code>, \u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/javascript.plainenglish.io\/how-to-use-react-hook-form-with-typescript-2cf597c0c45f\"><u>\u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/u><\/a><u>.<\/u><\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u044f \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u2014 \u0432\u044b \u043d\u0435 \u043f\u043e\u0436\u0430\u043b\u0435\u0435\u0442\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<h3>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<pre><code class=\"javascript\">import TextField from \"@material-ui\/core\/TextField\"; import React, { useState} from \"react\"; import {     Button,     Checkbox,     FormControlLabel,     FormLabel,     MenuItem,     Radio,     RadioGroup,     Select,     Slider } from \"@material-ui\/core\"; import {KeyboardDatePicker} from '@material-ui\/pickers'  const options = [     {         label: 'Dropdown Option 1',         value:'1'     },     {         label: 'Dropdown Option 2',         value:'2'     }, ]  const radioOptions = [     {         label: 'Radio Option 1',         value:'1'     },     {         label: 'Radio Option 2',         value:'2'     }, ]  const checkboxOptions = [     {         label: 'Checkbox Option 1',         value:'1'     },     {         label: 'Checkbox Option 2',         value:'2'     }, ]  const DATE_FORMAT = 'dd-MMM-yy'  export const FormBadDemo = () => {      const [textValue , setTextValue] = useState('');     const [dropdownValue , setDropDownValue] = useState('');     const [sliderValue , setSliderValue] = useState(0);     const [dateValue , setDateValue] = useState(new Date());     const [radioValue , setRadioValue] = useState('');     const [checkboxValue, setSelectedCheckboxValue] = useState&lt;any>([])      const onTextChange = (e:any) => setTextValue(e.target.value)     const onDropdownChange = (e:any) => setDropDownValue(e.target.value)     const onSliderChange = (e:any) => setSliderValue(e.target.value)     const onDateChange = (e:any) => setDateValue(e.target.value)     const onRadioChange = (e:any) => setRadioValue(e.target.value)      const handleSelect = (value:any) => {         const isPresent = checkboxValue.indexOf(value)         if (isPresent !== -1) {             const remaining = checkboxValue.filter((item:any) => item !== value)             setSelectedCheckboxValue(remaining)         } else {             setSelectedCheckboxValue((prevItems:any) => [...prevItems, value])         }     }      const handleSubmit = () => {         console.log({             textValue: textValue,             dropdownValue: dropdownValue,             sliderValue: sliderValue,             dateValue: dateValue,             radioValue: radioValue,             checkboxValue: checkboxValue,         })     }      const handleReset = () => {         setTextValue('')         setDropDownValue('')         setSliderValue(0)         setDateValue(new Date())         setRadioValue('')         setSelectedCheckboxValue('')     }      return &lt;form>          &lt;FormLabel component='legend'>Text Input&lt;\/FormLabel>         &lt;TextField             size='small'             error={false}             onChange={onTextChange}             value={textValue}             fullWidth             label={'text Value'}             variant='outlined'         \/>          &lt;FormLabel component='legend'>Dropdown Input&lt;\/FormLabel>         &lt;Select id='site-select' inputProps={{ autoFocus: true }} value={dropdownValue} onChange={onDropdownChange} >             {options.map((option: any) => {                 return (                     &lt;MenuItem key={option.value} value={option.value}>                         {option.label}                     &lt;\/MenuItem>                 )             })}         &lt;\/Select>          &lt;FormLabel component='legend'>Slider Input&lt;\/FormLabel>         &lt;Slider             value={sliderValue}             onChange={onSliderChange}             valueLabelDisplay='auto'             min={0}             max={100}             step={1}         \/>          &lt;FormLabel component='legend'>Date Input&lt;\/FormLabel>         &lt;KeyboardDatePicker             fullWidth             variant='inline'             defaultValue={new Date()}             id={`date-${Math.random()}`}             value={dateValue}             onChange={onDateChange}             rifmFormatter={(val) => val.replace(\/[^[a-zA-Z0-9-]*$]+\/gi, '')}             refuse={\/[^[a-zA-Z0-9-]*$]+\/gi}             autoOk             KeyboardButtonProps={{                 'aria-label': 'change date'             }}             format={DATE_FORMAT}         \/>          &lt;FormLabel component='legend'>Radio Input&lt;\/FormLabel>         &lt;RadioGroup aria-label='gender' value={radioValue} onChange={onRadioChange}>             {radioOptions.map((singleItem) => (                 &lt;FormControlLabel value={singleItem.value} control={&lt;Radio \/>} label={singleItem.label} \/>             ))}         &lt;\/RadioGroup>          &lt;FormLabel component='legend'>Checkbox Input&lt;\/FormLabel>         &lt;div>             {checkboxOptions.map(option =>                 &lt;Checkbox checked={checkboxValue.includes(option.value)} onChange={() => handleSelect(option.value)} \/>             )}         &lt;\/div>          &lt;Button onClick={handleSubmit} variant={'contained'} > Submit &lt;\/Button>         &lt;Button onClick={handleReset} variant={'outlined'}> Reset &lt;\/Button>      &lt;\/form> }<\/code><\/pre>\n<p><em>FormBadDemo.tsx<\/em><\/p>\n<p>\u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b. \u041d\u043e \u0443 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 <code>onChange<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e, \u0432 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u043c\u0441\u044f \u0440\u0435\u0436\u0438\u043c\u0435. \u0415\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430, \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043c\u0438 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u044d\u0442\u043e \u0442\u0430\u043a \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0442.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f<\/h3>\n<p>\u041a\u0430\u043a \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, <code>react-hook-form<\/code> \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430 HTML. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u0438\u043d\u0430\u0447\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Material-UI, Ant design \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 react-hook-form \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442-\u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>Controller<\/code> . \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0442\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>Controller<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"javascript\">&lt;Controller     name={name}     control={control}     render={({ field: { onChange, value }}) => (        &lt;AnyInputComponent           onChange={onChange}           value={value}         \/>     )} \/><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u044c \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0444\u043e\u0440\u043c, \u0442\u043e \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432\u0432\u043e\u0434\u0430 \u0432\u0430\u0436\u043d\u044b \u0434\u0432\u0430 \u043f\u043e\u043b\u044f. \u041e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445 \u2014 <code>value<\/code>, \u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u2014 <code>onChange<\/code>.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Controller \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0438 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c react-hook-form \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u043e \u043c\u0430\u0441\u043b\u0443! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044d\u0442\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438.<\/p>\n<h3>\u041f\u0440\u043e\u043f\u0441\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b<\/h3>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b \u043d\u0443\u0436\u043d\u044b \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u2014 <code>name<\/code> \u0438 <code>value<\/code>. \u042d\u0442\u0438 2 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u0432\u0441\u0435\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0442\u0438\u043f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 javascript, \u0432\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f.<\/p>\n<pre><code>export interface FormInputProps {     name: string     label: string }<\/code><\/pre>\n<p><em>FormInputProps.ts<\/em><\/p>\n<h3>\u0412\u0432\u043e\u0434 Text<\/h3>\n<p>\u042d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u0430, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Material UI.<\/p>\n<pre><code class=\"javascript\">import React from 'react' import { Controller, useFormContext } from 'react-hook-form' import TextField from '@material-ui\/core\/TextField' import {FormInputProps} from \".\/FormInputProps\";  export const FormInputText = ({ name, label }: FormInputProps) => {     const { control } = useFormContext()      return (         &lt;Controller             name={name}             control={control}             render={({ field: { onChange, value }, fieldState: { error }, formState }) => (                 &lt;TextField                     helperText={error ? error.message : null}                     size='small'                     error={!!error}                     onChange={onChange}                     value={value}                     fullWidth                     label={label}                     variant='outlined'                 \/>             )}         \/>     ) }<\/code><\/pre>\n<p><em>FormInputText.tsx<\/em><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>control<\/code> \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b <code>react-hook-form<\/code>. \u041e\u043d\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437 \u0445\u0443\u043a\u0430 <code>useForm()<\/code> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438, \u043a\u0430\u043a \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438. \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.<\/p>\n<h3>\u0412\u0432\u043e\u0434 Radio<\/h3>\n<p>\u0412\u0442\u043e\u0440\u044b\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0432\u0432\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 Radio. \u041a\u043e\u0434 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 material-ui \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"javascript\">import React from 'react' import { FormControl, FormControlLabel, FormHelperText, FormLabel, Radio, RadioGroup } from '@material-ui\/core' import { Controller, useFormContext } from 'react-hook-form' import {FormInputProps} from \".\/FormInputProps\";  const options = [     {         label: 'Radio Option 1',         value:'1'     },     {         label: 'Radio Option 2',         value:'2'     }, ]  export const FormInputRadio: React.FC&lt;FormInputProps> = ({ name, label }) => {     const { control, formState: { errors }} = useFormContext()      const errorMessage = errors[name] ? errors[name].message : null      return (         &lt;FormControl component='fieldset'>             &lt;FormLabel component='legend'>{label}&lt;\/FormLabel>             &lt;Controller                 name={name}                 control={control}                 render={({ field: { onChange, value }, fieldState: { error }, formState }) => (                     &lt;RadioGroup aria-label='gender' value={value} onChange={onChange}>                         {options.map((singleItem) => (                             &lt;FormControlLabel value={singleItem.value} control={&lt;Radio \/>} label={singleItem.label} \/>                         ))}                     &lt;\/RadioGroup>                 )}             \/>             &lt;FormHelperText color={'red'}>{errorMessage ? errorMessage : ''}&lt;\/FormHelperText>         &lt;\/FormControl>     ) }<\/code><\/pre>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <code>options<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u0438 \u0434\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0441\u0445\u043e\u0436\u0438 \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0412\u0432\u043e\u0434 Dropdown\u00a0<\/h3>\n<p>\u041d\u0430\u0448 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 &#8212; \u044d\u0442\u043e \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a (Dropdown). \u041f\u043e\u0447\u0442\u0438 \u043b\u044e\u0431\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u0432\u0438\u0434\u0435 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u041a\u043e\u0434 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 Dropdown \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<pre><code class=\"javascript\">import React from 'react' import { FormControl, InputLabel, MenuItem, Select } from '@material-ui\/core' import { useFormContext, Controller } from 'react-hook-form' import {FormInputProps} from \".\/FormInputProps\";  const options = [     {         label: 'Dropdown Option 1',         value:'1'     },     {         label: 'Dropdown Option 2',         value:'2'     }, ] export const FormInputDropdown: React.FC&lt;FormInputProps> = ({ name, label }) => {     const { control } = useFormContext()      const generateSingleOptions = () => {         return options.map((option: any) => {             return (                 &lt;MenuItem key={option.value} value={option.value}>                     {option.label}                 &lt;\/MenuItem>             )         })     }      return (         &lt;FormControl size={'small'}>             &lt;InputLabel>{label}&lt;\/InputLabel>             &lt;Controller                 render={({ field }) => (                     &lt;Select id='site-select' inputProps={{ autoFocus: true }} {...field}>                         {generateSingleOptions()}                     &lt;\/Select>                 )}                 control={control}                 name={name}             \/>         &lt;\/FormControl>     ) }<\/code><\/pre>\n<p><em>FormInputDropdown.tsx<\/em><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u043c\u044b \u0443\u0431\u0440\u0430\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0443 \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u043a\u0438. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c \u0436\u0435, \u043a\u0430\u043a Radio.<\/p>\n<h3>\u0412\u0432\u043e\u0434 Date<\/h3>\n<p>\u042d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u0442\u044b. \u0412 Material UI \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>Date<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u044b &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u044d\u0442\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<pre><code>yarn add @date-io\/date-fns@1.3.13 @material-ui\/pickers@3.3.10 date-fns@2.22.1<\/code><\/pre>\n<p>\u0411\u0443\u0434\u044c\u0442\u0435 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b \u0441 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0441\u0442\u044f\u043c. \u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439.<\/p>\n<pre><code class=\"javascript\">import React from 'react' import DateFnsUtils from '@date-io\/date-fns' import {KeyboardDatePicker, MuiPickersUtilsProvider} from '@material-ui\/pickers' import { Controller, useFormContext } from 'react-hook-form' import {FormInputProps} from \".\/FormInputProps\"; const DATE_FORMAT = 'dd-MMM-yy'  export const FormInputDate = ({ name, label }: FormInputProps) => {     const { control } = useFormContext()      return (         &lt;MuiPickersUtilsProvider utils={DateFnsUtils}>             &lt;Controller                 name={name}                 control={control}                 render={({ field, fieldState, formState }) => (                     &lt;KeyboardDatePicker                         fullWidth                         variant='inline'                         defaultValue={new Date()}                         id={`date-${Math.random()}`}                         label={label}                         rifmFormatter={(val) => val.replace(\/[^[a-zA-Z0-9-]*$]+\/gi, '')}                         refuse={\/[^[a-zA-Z0-9-]*$]+\/gi}                         autoOk                         KeyboardButtonProps={{                             'aria-label': 'change date'                         }}                         format={DATE_FORMAT}                         {...field}                     \/>                 )}             \/>         &lt;\/MuiPickersUtilsProvider>     ) }<\/code><\/pre>\n<p><em>FormInputDate.tsx<\/em><\/p>\n<p>\u042f \u0432\u044b\u0431\u0440\u0430\u043b <code>date-fns<\/code>. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>moment<\/code>.<\/p>\n<h3>\u0412\u0432\u043e\u0434 Checkbox\u00a0<\/h3>\n<p>\u042d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (\u0444\u043b\u0430\u0436\u043e\u043a). \u041d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0447\u0435\u0442\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441 react-hook-form. \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0432\u043e\u0434\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"javascript\">import React, { useEffect, useState } from 'react' import { Checkbox, FormControl, FormControlLabel, FormHelperText, FormLabel } from '@material-ui\/core' import { Controller, useFormContext } from 'react-hook-form' import {FormInputProps} from \".\/FormInputProps\";  const options = [     {         label: 'Checkbox Option 1',         value:'1'     },     {         label: 'Checkbox Option 2',         value:'2'     }, ]  export const FormInputCheckbox: React.FC&lt;FormInputProps> = ({ name, label }) => {     const [selectedItems, setSelectedItems] = useState&lt;any>([])     const { control, setValue, formState: { errors }} = useFormContext()      const handleSelect = (value:any) => {         const isPresent = selectedItems.indexOf(value)         if (isPresent !== -1) {             const remaining = selectedItems.filter((item:any) => item !== value)             setSelectedItems(remaining)         } else {             setSelectedItems((prevItems:any) => [...prevItems, value])         }     }      useEffect(() => {         setValue(name, selectedItems)     }, [selectedItems])      const errorMessage = errors[name] ? errors[name].message : null      return (         &lt;FormControl size={'small'} variant={'outlined'}>             &lt;FormLabel component='legend'>{label}&lt;\/FormLabel>              &lt;div>                 {options.map((option:any) => {                     return (                         &lt;FormControlLabel                             control={                                 &lt;Controller                                     name={name}                                     render={({ field: { onChange: onCheckChange } }) => {                                         return &lt;Checkbox checked={selectedItems.includes(option.value)} onChange={() => handleSelect(option.value)} \/>                                     }}                                     control={control}                                 \/>                             }                             label={option.label}                             key={option.value}                         \/>                     )                 })}             &lt;\/div>              &lt;FormHelperText>{errorMessage ? errorMessage : ''}&lt;\/FormHelperText>         &lt;\/FormControl>     ) }<\/code><\/pre>\n<p><em>FormInputCheckbox.tsx<\/em><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u0435\u0442\u0435 \u0435\u043c\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0446\u0438\u0439, \u0438 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043d\u0430\u0434\u043e!<\/p>\n<h3>\u0412\u0432\u043e\u0434 Slider<\/h3>\n<p>\u041d\u0430\u0448 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 &#8212; \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Slider (\u0441\u043b\u0430\u0439\u0434\u0435\u0440). \u041e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c. \u041a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/p>\n<pre><code class=\"javascript\">import React, {ChangeEvent, useEffect} from 'react' import { FormLabel, Slider} from '@material-ui\/core' import { Controller, useFormContext } from 'react-hook-form' import {FormInputProps} from \".\/FormInputProps\";  export const FormInputSlider = ({ name, label }: FormInputProps) => {      const { control , watch} = useFormContext()     const [value, setValue] = React.useState&lt;number>(30);      const formValue = watch(name)     useEffect(() => {         if (value) setValue(formValue)     }, [formValue])      const handleChange = (event: any, newValue: number | number[]) => {         setValue(newValue as number);     };      return (         &lt;>             &lt;FormLabel component='legend'>{label}&lt;\/FormLabel>             &lt;Controller                 name={name}                 control={control}                 render={({ field, fieldState, formState }) => (                     &lt;Slider                         {...field}                         value={value}                         onChange={handleChange}                         valueLabelDisplay='auto'                         min={0}                         max={100}                         step={1}                     \/>                 )}             \/>         &lt;\/>     ) }<\/code><\/pre>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>handleChange<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u0432\u0443\u0445\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c \u0441\u043b\u0430\u0439\u0434\u0435\u0440\u043e\u043c (\u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430). \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 <code>number<\/code> \u043d\u0430 <code>number[]<\/code>.<\/p>\n<h3>\u0421\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435 \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438.<\/p>\n<pre><code class=\"javascript\">import {Button, Paper, Typography} from \"@material-ui\/core\"; import { FormProvider, useForm } from 'react-hook-form' import {FormInputText} from \".\/form-components\/FormInputText\"; import {FormInputCheckbox} from \".\/form-components\/FormInputCheckbox\"; import {FormInputDropdown} from \".\/form-components\/FormInputDropdown\"; import {FormInputDate} from \".\/form-components\/FormInputDate\"; import {FormInputSlider} from \".\/form-components\/FormInputSlider\"; import {FormInputRadio} from \".\/form-components\/FormInputRadio\";  export const FormDemo = () => {     const methods = useForm({defaultValues: defaultValues})     const { handleSubmit, reset } = methods     const onSubmit = (data) => console.log(data)          return &lt;Paper style={{display:\"grid\" , gridRowGap:'20px' , padding:\"20px\"}}>         &lt;FormProvider {...methods}>             &lt;FormInputText name='textValue' label='Text Input' \/>             &lt;FormInputRadio name={'radioValue'} label={'Radio Input'}\/>             &lt;FormInputDropdown name='dropdownValue' label='Dropdown Input' \/>             &lt;FormInputDate name='dateValue' label='Date Input' \/>             &lt;FormInputCheckbox name={'checkboxValue'} label={'Checkbox Input'}  \/>             &lt;FormInputSlider name={'sliderValue'} label={'Slider Input'}  \/>         &lt;\/FormProvider>         &lt;Button onClick={handleSubmit(onSubmit)} variant={'contained'} > Submit &lt;\/Button>         &lt;Button onClick={() => reset()} variant={'outlined'}> Reset &lt;\/Button>     &lt;\/Paper> }<\/code><\/pre>\n<p><em>FormDemo.tsx<\/em><\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0430\u0448\u0430 \u0444\u043e\u0440\u043c\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. <\/p>\n<hr\/>\n<p>React-hooks \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0432 React \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 16.8, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0443\u0436\u0435 \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e. \u0412\u0441\u0435\u0445 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 \u0434\u0432\u0443\u0445\u0434\u043d\u0435\u0432\u043d\u044b\u0439 \u043e\u043d\u043b\u0430\u0439\u043d-\u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 React-hooks, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c hooks, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 hooks.\u041f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 react-testing-library \u0438 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 hooks. \u0418\u043d\u0442\u0435\u043d\u0441\u0438\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d frontend JavaScript \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c React \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 <a href=\"https:\/\/otus.pw\/a6zR\/\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.  <\/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\/company\/otus\/blog\/653017\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/653017\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041e\u0447\u0438\u0441\u0442\u043a\u0430 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e React Hook Form \u0438 Material UI  <\/h2>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>React Hook Form \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b \u0432 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 React.<\/p>\n<p>\u041d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c React Hook Form \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 Material UI.<\/p>\n<h3>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>react-hook-form<\/code>. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>react-hook-form<\/code>, \u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/javascript.plainenglish.io\/how-to-use-react-hook-form-with-typescript-2cf597c0c45f\"><u>\u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/u><\/a><u>.<\/u><\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u044f \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u2014 \u0432\u044b \u043d\u0435 \u043f\u043e\u0436\u0430\u043b\u0435\u0435\u0442\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<h3>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<pre><code class=\"javascript\">import TextField from \"@material-ui\/core\/TextField\"; import React, { useState} from \"react\"; import {     Button,     Checkbox,     FormControlLabel,     FormLabel,     MenuItem,     Radio,     RadioGroup,     Select,     Slider } from \"@material-ui\/core\"; import {KeyboardDatePicker} from '@material-ui\/pickers'  const options = [     {         label: 'Dropdown Option 1',         value:'1'     },     {         label: 'Dropdown Option 2',         value:'2'     }, ]  const radioOptions = [     {         label: 'Radio Option 1',         value:'1'     },     {         label: 'Radio Option 2',         value:'2'     }, ]  const checkboxOptions = [     {         label: 'Checkbox Option 1',         value:'1'     },     {         label: 'Checkbox Option 2',         value:'2'     }, ]  const DATE_FORMAT = 'dd-MMM-yy'  export const FormBadDemo = () => {      const [textValue , setTextValue] = useState('');     const [dropdownValue , setDropDownValue] = useState('');     const [sliderValue , setSliderValue] = useState(0);     const [dateValue , setDateValue] = useState(new Date());     const [radioValue , setRadioValue] = useState('');     const [checkboxValue, setSelectedCheckboxValue] = useState&lt;any>([])      const onTextChange = (e:any) => setTextValue(e.target.value)     const onDropdownChange = (e:any) => setDropDownValue(e.target.value)     const onSliderChange = (e:any) => setSliderValue(e.target.value)     const onDateChange = (e:any) => setDateValue(e.target.value)     const onRadioChange = (e:any) => setRadioValue(e.target.value)      const handleSelect = (value:any) => {         const isPresent = checkboxValue.indexOf(value)         if (isPresent !== -1) {             const remaining = checkboxValue.filter((item:any) => item !== value)             setSelectedCheckboxValue(remaining)         } else {             setSelectedCheckboxValue((prevItems:any) => [...prevItems, value])         }     }      const handleSubmit = () => {         console.log({             textValue: textValue,             dropdownValue: dropdownValue,             sliderValue: sliderValue,             dateValue: dateValue,             radioValue: radioValue,             checkboxValue: checkboxValue,         })     }      const handleReset = () => {         setTextValue('')         setDropDownValue('')         setSliderValue(0)         setDateValue(new Date())         setRadioValue('')         setSelectedCheckboxValue('')     }      return &lt;form>          &lt;FormLabel component='legend'>Text Input&lt;\/FormLabel>         &lt;TextField             size='small'             error={false}             onChange={onTextChange}             value={textValue}             fullWidth             label={'text Value'}             variant='outlined'         \/>          &lt;FormLabel component='legend'>Dropdown Input&lt;\/FormLabel>         &lt;Select id='site-select' inputProps={{ autoFocus: true }} value={dropdownValue} onChange={onDropdownChange} >             {options.map((option: any) => {                 return (                     &lt;MenuItem key={option.value} value={option.value}>                         {option.label}                     &lt;\/MenuItem>                 )             })}         &lt;\/Select>          &lt;FormLabel component='legend'>Slider Input&lt;\/FormLabel>         &lt;Slider             value={sliderValue}             onChange={onSliderChange}             valueLabelDisplay='auto'             min={0}             max={100}             step={1}         \/>          &lt;FormLabel component='legend'>Date Input&lt;\/FormLabel>         &lt;KeyboardDatePicker             fullWidth             variant='inline'             defaultValue={new Date()}             id={`date-${Math.random()}`}             value={dateValue}             onChange={onDateChange}             rifmFormatter={(val) => val.replace(\/[^[a-zA-Z0-9-]*$]+\/gi, '')}             refuse={\/[^[a-zA-Z0-9-]*$]+\/gi}             autoOk             KeyboardButtonProps={{                 'aria-label': 'change date'             }}             format={DATE_FORMAT}         \/>          &lt;FormLabel component='legend'>Radio Input&lt;\/FormLabel>         &lt;RadioGroup aria-label='gender' value={radioValue} onChange={onRadioChange}>             {radioOptions.map((singleItem) => (                 &lt;FormControlLabel value={singleItem.value} control={&lt;Radio \/>} label={singleItem.label} \/>             ))}         &lt;\/RadioGroup>          &lt;FormLabel component='legend'>Checkbox Input&lt;\/FormLabel>         &lt;div>             {checkboxOptions.map(option =>                 &lt;Checkbox checked={checkboxValue.includes(option.value)} onChange={() => handleSelect(option.value)} \/>             )}         &lt;\/div>          &lt;Button onClick={handleSubmit} variant={'contained'} > Submit &lt;\/Button>         &lt;Button onClick={handleReset} variant={'outlined'}> Reset &lt;\/Button>      &lt;\/form> }<\/code><\/pre>\n<p><em>FormBadDemo.tsx<\/em><\/p>\n<p>\u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b. \u041d\u043e \u0443 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 <code>onChange<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e, \u0432 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u043c\u0441\u044f \u0440\u0435\u0436\u0438\u043c\u0435. \u0415\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430, \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043c\u0438 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u044d\u0442\u043e \u0442\u0430\u043a \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0442.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f<\/h3>\n<p>\u041a\u0430\u043a \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, <code>react-hook-form<\/code> \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430 HTML. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u0438\u043d\u0430\u0447\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Material-UI, Ant design \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 react-hook-form \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442-\u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>Controller<\/code> . \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0442\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>Controller<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"javascript\">&lt;Controller     name={name}     control={control}     render={({ field: { onChange, value }}) => (        &lt;AnyInputComponent           onChange={onChange}           value={value}         \/>     )} \/><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u044c \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0444\u043e\u0440\u043c, \u0442\u043e \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432\u0432\u043e\u0434\u0430 \u0432\u0430\u0436\u043d\u044b \u0434\u0432\u0430 \u043f\u043e\u043b\u044f. \u041e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445 \u2014 <code>value<\/code>, \u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u2014 <code>onChange<\/code>.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Controller \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0438 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c react-hook-form \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u043e \u043c\u0430\u0441\u043b\u0443! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044d\u0442\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438.<\/p>\n<h3>\u041f\u0440\u043e\u043f\u0441\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b<\/h3>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b \u043d\u0443\u0436\u043d\u044b \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u2014 <code>name<\/code> \u0438 <code>value<\/code>. \u042d\u0442\u0438 2 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u0432\u0441\u0435\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0442\u0438\u043f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 javascript, \u0432\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f.<\/p>\n<pre><code>export interface FormInputProps {     name: string     label: string }<\/code><\/pre>\n<p><em>FormInputProps.ts<\/em><\/p>\n<h3>\u0412\u0432\u043e\u0434 Text<\/h3>\n<p>\u042d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u0430, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Material UI.<\/p>\n<pre><code class=\"javascript\">import React from 'react' import { Controller, useFormContext } from 'react-hook-form' import TextField from '@material-ui\/core\/TextField' import {FormInputProps} from \".\/FormInputProps\";  export const FormInputText = ({ name, label }: FormInputProps) => {     const { control } = useFormContext()      return (         &lt;Controller             name={name}             control={control}             render={({ field: { onChange, value }, fieldState: { error }, formState }) => (                 &lt;TextField                     helperText={error ? error.message : null}                     size='small'                     error={!!error}                     onChange={onChange}                     value={value}                     fullWidth                     label={label}                     variant='outlined'                 \/>             )}         \/>     ) }<\/code><\/pre>\n<p><em>FormInputText.tsx<\/em><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>control<\/code> \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b <code>react-hook-form<\/code>. \u041e\u043d\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437 \u0445\u0443\u043a\u0430 <code>useForm()<\/code> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438, \u043a\u0430\u043a \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438. \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.<\/p>\n<h3>\u0412\u0432\u043e\u0434 Radio<\/h3>\n<p>\u0412\u0442\u043e\u0440\u044b\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0432\u0432\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 Radio. \u041a\u043e\u0434 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 material-ui \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"javascript\">import React from 'react' import { FormControl, FormControlLabel, FormHelperText, FormLabel, Radio, RadioGroup } from '@material-ui\/core' import { Controller, useFormContext } from 'react-hook-form' import {FormInputProps} from \".\/FormInputProps\";  const options = [     {         label: 'Radio Option 1',         value:'1'     },     {         label: 'Radio Option 2',         value:'2'     }, ]  export const FormInputRadio: React.FC&lt;FormInputProps> = ({ name, label }) => {     const { control, formState: { errors }} = useFormContext()      const errorMessage = errors[name] ? errors[name].message : null      return (         &lt;FormControl component='fieldset'>             &lt;FormLabel component='legend'>{label}&lt;\/FormLabel>             &lt;Controller                 name={name}                 control={control}                 render={({ field: { onChange, value }, fieldState: { error }, formState }) => (                     &lt;RadioGroup aria-label='gender' value={value} onChange={onChange}>                         {options.map((singleItem) => (                             &lt;FormControlLabel value={singleItem.value} control={&lt;Radio \/>}<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-329966","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329966","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=329966"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329966\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=329966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=329966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=329966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}