{"id":335592,"date":"2022-07-11T21:00:13","date_gmt":"2022-07-11T21:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=335592"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=335592","title":{"rendered":"<span>\u041d\u0435\u0434\u043e\u043e\u0446\u0435\u043d\u0435\u043d\u043d\u0430\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u0434\u043b\u044f HOC\u2019\u043e\u0432 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0445\u0443\u043a\u043e\u0432 \u0432 react \u0438 \u043f\u0440\u0438 \u0447\u0435\u043c \u0437\u0434\u0435\u0441\u044c React.CloneElement?<\/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 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438  react-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043a\u0443\u0441\u043e\u043a \u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u044f\u0441\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0423 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b\u0441\u043b\u044c \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e HOC (hight order component \u0438\u043b\u0438 \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430) \u0438\u043b\u0438 \u0436\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0445\u0443\u043a\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u043c \u0443\u0436\u0435 \u0432\u0441\u0435\u043c \u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0437\u043d\u0430\u0435\u0442\u0435 \u0434\u0430\u0436\u0435 \u043b\u0443\u0447\u0448\u0435 \u043c\u0435\u043d\u044f (\u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0436\u0435 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043d\u0438\u043c\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435, \u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e, \u0432\u044b \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b).<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0435 \u0434\u043b\u044f \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u0437\u0430\u0441\u043b\u0443\u0436\u0435\u043d\u043d\u043e \u043e\u0431\u0445\u043e\u0434\u044f\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043e\u0431\u0437\u043e\u0440\u0430\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 react-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0435, \u043d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0435\u0439\u0441\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432\u0443 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434, \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0430\u0447\u0430\u0442\u044c \u043d\u0435 \u0441 \u0435\u0433\u043e \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0430 \u0441 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0432\u0435\u0441\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430.<\/p>\n<h3>\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f ui-kit \u0441 \u043d\u0443\u043b\u044f. \u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u0440\u0430\u0437\u043c\u044b\u0448\u043b\u044f\u0442\u044c \u043d\u0430\u0434 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u043a\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p>\u041a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0434\u0438\u0437\u0430\u0439\u043d \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b:<\/p>\n<ol>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0443\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0444\u043e\u0440\u043c\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Select \u0438\u0437 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442\u043e \u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0445\u043e\u0442\u044c \u043c\u0430\u043b\u0435\u0439\u0448\u0438\u0445 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 c\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0433\u0430 <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/HTML\/Element\/form\" rel=\"noopener noreferrer nofollow\">form<\/a> \u0438\u0437 HTML5<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438\u0437 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0445\u0443\u043a\u0430 (\u044d\u0442\u043e \u0443\u0436\u0435 \u043c\u043e\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435, \u0442.\u043a. \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0447\u0435\u043c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b)<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"markdown\">\u251c\u2500\u2500 components\/ \u2502   \u251c\u2500\u2500 Form\/ (\u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u0441\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u044e\u0434\u0430) \u2502   \u2502   \u251c\u2500\u2500 Form.hooks.ts \u2502   \u2502   \u2514\u2500\u2500 Form.tsx \u2502   \u251c\u2500\u2500 Input\/ \u2502   \u2502   \u2514\u2500\u2500 Input.tsx \u2502   \u251c\u2500\u2500 Select \u2502   \u2502   \u2514\u2500\u2500 Select.tsx \u2502   \u2514\u2500\u2500 ...other components (\u0441\u043e\u0442\u043d\u044f-\u0434\u0440\u0443\u0433\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439 \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b) \u251c\u2500\u2500 App.tsx \u2514\u2500\u2500 index.ts <\/code><\/pre>\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 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0432\u0435\u0434\u044c \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435  \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b \u0432 \u043c\u0438\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c, \u0430 \u0434\u0435\u0442\u0430\u043b\u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u043c):<\/p>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/Form.tsx *\/  type FormProps = {   children?: React.ReactNode;   \/** ...\u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u043f\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 *\/ }  \/** \u0421\u0430\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0442\u0440\u0438\u0441\u0443\u044e\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f *\/ export const Form: React.FC&lt;FormProps> = ({ children, ...restProps }) => {   \/**    * ...\u0442\u0443\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0443\u0436\u043d\u0430 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443    *\/   return &lt;form {...restProps}>{children}&lt;\/form>; }; <\/code><\/pre>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/Form.hooks.tsx *\/  type IUseFormStateProps = {   \/** ...\u043d\u0443\u0436\u043d\u044b\u0435 props \u0434\u043b\u044f \u0445\u0443\u043a\u0430 *\/ }  \/** \u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0445\u0443\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b *\/ export const useFormState = ({ initialState = {} }: IUseFormStateProps) => {   const [state, setState] = useState(initialState)    const updateValues = useCallback(({name, value}: { name: string; value: any }) => {     setState(((prevState) => ({...prevState, ...{[name]: value}})))   }, []);    return {     state,     handlers: {       updateValues,     },   }; }; <\/code><\/pre>\n<p>\u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:<\/p>\n<pre><code class=\"typescript\">\/** src\/App.tsx *\/  function App() {   const { state, handlers } = useFormState({});    return (     &lt;div className=\"App\">       &lt;Form>         &lt;Input           name=\"username\"           value={state.username}           onChange={(value) =>             handlers.updateValues({ name: \"username\", value })           }         \/>         &lt;Input           name=\"password\"           value={state.password}           onChange={(value) =>             handlers.updateValues({ name: \"password\", value })           }         \/>         &lt;Select           name={\"gender\"}           list={[...]}           value={state.gender}           onChange={(value) => handlers.updateValues({ name: \"gender\", value })}         \/>       &lt;\/Form>     &lt;\/div>   ); }  export default App; <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u0435\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043f\u043e\u0434\u0441\u0432\u0435\u0447\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043d\u0435\u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043d\u043e \u0440\u0430\u0437\u0434\u0443\u043b\u0438\u0441\u044c \u043d\u0430\u0448\u0438 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u0432 \u0442\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0433\u0434\u0435 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 value \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a onChange. \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0448\u0435\u0439 \u0444\u043e\u0440\u043c\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0440\u0443\u043a\u0430\u043c\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u0442\u044c \u0435\u0433\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 value, \u0430 \u043a\u0430\u043a\u043e\u0439 \u0443 \u043d\u0435\u0433\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c onChange? \u0410 \u043e\u0431\u0449\u0438\u0435 \u0441\u0442\u0438\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c, \u0432\u0434\u0440\u0443\u0433 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043d\u0438\u0445 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u0430\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430? \u0410 \u043a\u0430\u043a \u0436\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Don%E2%80%99t_repeat_yourself\" rel=\"noopener noreferrer nofollow\">DRY<\/a>, \u0442\u0443\u0442 \u044f\u0432\u043d\u043e \u0436\u0435 \u0438\u043c \u043d\u0435 \u043f\u0430\u0445\u043d\u0435\u0442 \u0434\u0430\u0436\u0435? \u0410 \u043a\u0430\u043a \u0436\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0438\u0434\u0435?<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044d\u0442\u043e \u0436\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430! \u041f\u0440\u043e\u0431\u043b\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445 onChange, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432 state \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435 value \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<p>\u041d\u0430\u0448 \u0434\u043e\u043b\u0433, \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f? \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u0441\u044e \u043e\u0431\u0449\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e \u0441\u0432\u044f\u0437\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b \u0438 \u0435\u0435 \u043f\u043e\u043b\u0435\u0439 (\u0438\u043d\u043f\u0443\u0442\u044b, \u0441\u0435\u043b\u0435\u043a\u0442\u044b, \u0447\u0435\u043a\u0431\u043e\u043a\u0441\u044b) \u0432 \u043e\u0434\u043d\u0443 \u043e\u0431\u0435\u0440\u0442\u043a\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f HOC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0444\u043e\u0440\u043c\u044b. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/Form.tsx *\/  \/**  *\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b React.Context,  *\u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e \u0434\u0430\u043d\u043d\u044b\u0445  *  \u043d\u0438\u0436\u0435 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432  *\/ type IFormContext = {   \/** ...\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0432\u0441\u0435-\u0432\u0441\u0435, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b *\/ };  export const FormContext = React.createContext&lt;IFormContext>({   state: {},   handlers: {     updateValues: () => console.error(\"not initialized\"),   }, });  type FormProps = {   formEntity: IFormContext;   children?: React.ReactNode;   \/** ... *\/ };  export const Form: React.FC&lt;FormProps> = ({   children,   formEntity,   ...restProps }) => {   \/**    * ...    *\/   return (     &lt;FormContext.Provider value={formEntity}>       &lt;form {...restProps}>{children}&lt;\/form>     &lt;\/FormContext.Provider>   ); }; <\/code><\/pre>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/withFormState.tsx *\/  \/** \u041a\u0430\u043a \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e HOC'a *\/ export const withFormState = &lt;   T extends WithFormStateProps = WithFormStateProps >(   WrappedComponent: React.ComponentType&lt;T>,   name: string ) => {   const { state, handlers } = useContext(FormContext);   const value = state[name]?.value || null;    const hocComponent = ({ ...props }) => (     &lt;WrappedComponent {...props} name={name} value={value} \/>   );    return hocComponent; }; <\/code><\/pre>\n<p>\u0418 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p>\n<pre><code class=\"typescript\">\/** src\/App.tsx *\/  function App() {   const formEntity = useFormState({});    const UsernameField = withFormState(Input, \"name\");   const PasswordField = withFormState(Input, \"password\");   const GenderField = withFormState(Select, \"gender\");    return (     &lt;div className=\"App\">       &lt;Form formEntity={formEntity}>         &lt;UsernameField \/>         &lt;PasswordField \/>         &lt;GenderField \/>       &lt;\/Form>     &lt;\/div>   ); }  export default App; <\/code><\/pre>\n<p>\u041c-\u0434\u0430, \u0438\u0437\u044f\u0449\u0435\u0441\u0442\u0432\u0430 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043c\u0430\u043b\u043e\u0432\u0430\u0442\u043e. \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 HOC\u2019a \u0432 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0443\u0436\u0435 \u0441 \u043d\u0438\u043c.<\/p>\n<pre><code class=\"markdown\">\u251c\u2500\u2500 components\/ \u2502   \u251c\u2500\u2500 Form\/ \u2502   \u2502   \u251c\u2500\u2500 Form.hooks.ts \u2502   \u2502   \u2514\u2500\u2500 Form.tsx \u2502   \u251c\u2500\u2500 Input\/ \u2502   \u2502   \u251c\u2500\u2500 Input.tsx \u2502   \u2502   \u2514\u2500\u2500 ! EnhancedInput.tsx (\u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0441\u044e\u0434\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u043e\u0439 \u0438\u043d\u043f\u0443\u0442) \u2502   \u251c\u2500\u2500 Select\/ \u2502   \u2502   \u251c\u2500\u2500 Select.tsx \u2502   \u2502   \u2514\u2500\u2500 ! EnhancedSelect.tsx (\u0438 \u0441\u044e\u0434\u0430...) \u2502   \u2514\u2500\u2500 ...other components (\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435?) \u251c\u2500\u2500 App.tsx \u2514\u2500\u2500 index.ts <\/code><\/pre>\n<pre><code class=\"typescript\">\/** src\/components\/Input\/EnhancedInput.tsx *\/  type EnhancedInputProps = {   name: string; } &amp; InputProps;  \/** \u041a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u0438 Enchanced \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c *\/ export const EnhancedInput: React.FC&lt;EnhancedInputProps> = ({ name, ...restProps }) => {   const ResultComponent = withFormState(Input, name)        return &lt;ResultComponent {...restProps} \/>; }; <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438 \u043b\u0443\u0447\u0448\u0435, \u0442\u043e \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u0444\u043e\u0440\u043c\u044b? \u0418\u043d\u043f\u0443\u0442\u044b, \u0441\u0435\u043b\u0435\u043a\u0442\u044b, \u0447\u0435\u043a\u0431\u043e\u043a\u0441\u044b \u0443\u0436\u0435 \u0438 \u0442\u0430\u043a \u0435\u0441\u0442\u044c \u0432 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435, <strong>\u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043b\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/strong>!<\/p>\n<p>\u041c\u044b\u0441\u043b\u0438 \u0436\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0445\u0443\u043a\u043e\u0432 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0434\u0443\u0442 \u043d\u0430\u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0442\u0443\u043f\u0438\u043a. \u0422\u0430\u043a \u0436\u0435 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0440\u0435\u0434\u043a\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442<\/h3>\n<p>\u041f\u043e\u0434 react \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438, \u0430 \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u043e\u0439 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043c\u0438\u0440\u0435 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0422\u0430\u043a \u043a\u0430\u043a \u0436\u0435 \u0440\u0435\u0448\u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/ant.design\/\" rel=\"noopener noreferrer nofollow\">ant design<\/a>? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 (\u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <a href=\"https:\/\/ant.design\/components\/form\/\" rel=\"noopener noreferrer nofollow\">Form<\/a> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 antd:<\/p>\n<pre><code class=\"typescript\">import { Button, Checkbox, Form, Input } from 'antd'; import React from 'react';  const AntdExample: React.FC = () => {   const onFinish = (values: any) => {     console.log('Success:', values);   };    const onFinishFailed = (errorInfo: any) => {     console.log('Failed:', errorInfo);   };    return (     &lt;Form       onFinish={onFinish}       onFinishFailed={onFinishFailed}     >       &lt;Form.Item         label=\"Username\"         name=\"username\"       >         &lt;Input \/>       &lt;\/Form.Item>        &lt;Form.Item         label=\"Password\"         name=\"password\"       >         &lt;Input.Password \/>       &lt;\/Form.Item>        &lt;Form.Item name=\"remember\">         &lt;Checkbox>Remember me&lt;\/Checkbox>       &lt;\/Form.Item>        &lt;Form.Item>         &lt;Button type=\"primary\" htmlType=\"submit\">           Submit         &lt;\/Button>       &lt;\/Form.Item>     &lt;\/Form>   ); };  export default AntdExample; <\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u0438\u0437\u044f\u0449\u043d\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0433\u043b\u0430\u0437 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 value \u0438 onChange (<strong>\u0438 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435!<\/strong>) \u043a \u043f\u043e\u043b\u044f\u043c \u0444\u043e\u0440\u043c\u044b \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 <a href=\"https:\/\/ant.design\/components\/form\/#Form.Item\" rel=\"noopener noreferrer nofollow\">Form.Item<\/a> \u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0438\u043d\u043f\u0443\u0442\u043e\u0432! \u041d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0432\u044f\u0436\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 children \u0438 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e! \u041d\u043e \u0433\u0434\u0435 \u0436\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0435 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043d\u0438\u0435 props? \u0415\u0441\u043b\u0438 \u0433\u0434\u0435-\u0442\u043e \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0435 props, \u0442\u043e \u043a\u0430\u043a \u043e\u043d\u0438 \u043d\u0435 \u043c\u0435\u0448\u0430\u044e\u0442 \u0441\u0442\u0430\u0440\u044b\u043c \u043f\u0440\u043e\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u043c props \u0440\u0443\u043a\u0430\u043c\u0438 \u0438\u0437 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438? \u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0441\u0430\u043c\u044b\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u0441\u0435\u0433\u043e \u043b\u0435\u0436\u0438\u0442 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041e\u0431\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, Form.Item \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u0432\u0438\u0434\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 2 \u0432\u0435\u0449\u0438:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0443\u0436\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e name)<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 value, onChange \u0438 \u0442.\u0434., \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (\u0430\u0433\u0430, \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0431\u0435\u043d\u043a\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 Form.Item), \u0447\u0435\u0440\u0435\u0437 \u0435\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 (\u0414\u0430, \u0432\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u043b\u0438. \u0412\u044b \u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u043e <a href=\"https:\/\/ru.reactjs.org\/docs\/react-api.html#cloneelement\" rel=\"noopener noreferrer nofollow\">React.CloneElement<\/a>?)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"typescript\">type FormItemProps {     name: string;     className?: string; \/** \u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a props \u0443 children, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e ReactElement  *\/     children?: ReactElement; }  \/** \u041d\u0430\u0448 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 Form.Item \u0438\u0437 antd *\/ export const FormItem = ({ children, className, name }: ItemProps) =>  { \/** \u0414\u043e\u0441\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430\u0448\u0435\u0439 \u0444\u043e\u0440\u043c\u044b *\/     const { state, handlers } = useContext(FormContext);      const value = state?.[name]?.value || null;     const handleChange = (value) => handlers.updateValues({ name: name, value: value });  \/** \u0413\u043e\u0442\u043e\u0432\u0438\u043c props, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u043c\u0435\u0448\u0430\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 *\/     const injectionProps = {         value,         onChange: handleChange,     };  \/** \u0414\u0435\u043b\u0430\u0435\u043c \u0441\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0438 \u0441\u0442\u0430\u0440\u044b\u0445 props, \u0432\u0435\u0434\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c props \u0432 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435 \u0441\u043d\u0430\u0440\u0443\u0436\u0438 *\/     const childProps = { ...(children.props || {}), ...injectionProps };  \/** \u041a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0441 \u0443\u0436\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 props *\/ const clonedElement = React.cloneElement(children, childProps)  \/** \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0443\u044e \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443*\/     return &lt;div className={className}>{clonedElement}&lt;\/div>; } <\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0444\u043e\u0440\u043c\u044b \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u0432\u044b\u0433\u043d\u0430\u0442\u044c \u043d\u0430\u0441 \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"typescript\">\/** src\/App.tsx *\/  \/** \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b, \u043d\u043e \u0443\u0436\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c *\/ function App() {   const formEntity = useFormState({});    return (     &lt;div className=\"App\">       &lt;Form formEntity={formEntity}>         &lt;FormItem name=\"username\">           &lt;Input \/>         &lt;\/FormItem>         &lt;FormItem name=\"password\">           &lt;Input \/>         &lt;\/FormItem>         &lt;FormItem name=\"gender\">           &lt;Select list={[...]} \/>         &lt;\/FormItem>       &lt;\/Form>     &lt;\/div>   ); }  export default App; <\/code><\/pre>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u043e\u043f\u044b\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u043d\u044e\u0430\u043d\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0433\u043e\u0442\u043e\u0432 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043f\u043e\u043a\u043e\u043b\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0434 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c children \u0438 \u0442.\u043f.), \u043d\u043e \u0441\u0430\u043c \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043c\u043e\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u044f \u0441\u043c\u043e\u0433 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0432\u0430\u0448 \u0430\u0440\u0441\u0435\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f react-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0435\u0449\u0435 \u043d\u0430 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u0435\u043c.<\/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\/676384\/\"> https:\/\/habr.com\/ru\/post\/676384\/<\/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 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438  react-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043a\u0443\u0441\u043e\u043a \u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u044f\u0441\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0423 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b\u0441\u043b\u044c \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e HOC (hight order component \u0438\u043b\u0438 \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430) \u0438\u043b\u0438 \u0436\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0445\u0443\u043a\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u043c \u0443\u0436\u0435 \u0432\u0441\u0435\u043c \u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0437\u043d\u0430\u0435\u0442\u0435 \u0434\u0430\u0436\u0435 \u043b\u0443\u0447\u0448\u0435 \u043c\u0435\u043d\u044f (\u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0436\u0435 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043d\u0438\u043c\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435, \u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e, \u0432\u044b \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b).<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0435 \u0434\u043b\u044f \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u0437\u0430\u0441\u043b\u0443\u0436\u0435\u043d\u043d\u043e \u043e\u0431\u0445\u043e\u0434\u044f\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043e\u0431\u0437\u043e\u0440\u0430\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 react-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0435, \u043d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0435\u0439\u0441\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432\u0443 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434, \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0430\u0447\u0430\u0442\u044c \u043d\u0435 \u0441 \u0435\u0433\u043e \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0430 \u0441 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0432\u0435\u0441\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430.<\/p>\n<h3>\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f ui-kit \u0441 \u043d\u0443\u043b\u044f. \u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u0440\u0430\u0437\u043c\u044b\u0448\u043b\u044f\u0442\u044c \u043d\u0430\u0434 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u043a\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p>\u041a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0434\u0438\u0437\u0430\u0439\u043d \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b:<\/p>\n<ol>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0443\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0444\u043e\u0440\u043c\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Select \u0438\u0437 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442\u043e \u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0445\u043e\u0442\u044c \u043c\u0430\u043b\u0435\u0439\u0448\u0438\u0445 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 c\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0433\u0430 <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/HTML\/Element\/form\" rel=\"noopener noreferrer nofollow\">form<\/a> \u0438\u0437 HTML5<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438\u0437 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0445\u0443\u043a\u0430 (\u044d\u0442\u043e \u0443\u0436\u0435 \u043c\u043e\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435, \u0442.\u043a. \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0447\u0435\u043c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b)<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"markdown\">\u251c\u2500\u2500 components\/ \u2502   \u251c\u2500\u2500 Form\/ (\u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u0441\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u044e\u0434\u0430) \u2502   \u2502   \u251c\u2500\u2500 Form.hooks.ts \u2502   \u2502   \u2514\u2500\u2500 Form.tsx \u2502   \u251c\u2500\u2500 Input\/ \u2502   \u2502   \u2514\u2500\u2500 Input.tsx \u2502   \u251c\u2500\u2500 Select \u2502   \u2502   \u2514\u2500\u2500 Select.tsx \u2502   \u2514\u2500\u2500 ...other components (\u0441\u043e\u0442\u043d\u044f-\u0434\u0440\u0443\u0433\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439 \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b) \u251c\u2500\u2500 App.tsx \u2514\u2500\u2500 index.ts <\/code><\/pre>\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 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0432\u0435\u0434\u044c \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435  \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b \u0432 \u043c\u0438\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u043c, \u0430 \u0434\u0435\u0442\u0430\u043b\u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u043c):<\/p>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/Form.tsx *\/  type FormProps = {   children?: React.ReactNode;   \/** ...\u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u043f\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 *\/ }  \/** \u0421\u0430\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0442\u0440\u0438\u0441\u0443\u044e\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f *\/ export const Form: React.FC&lt;FormProps> = ({ children, ...restProps }) => {   \/**    * ...\u0442\u0443\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0443\u0436\u043d\u0430 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443    *\/   return &lt;form {...restProps}>{children}&lt;\/form>; }; <\/code><\/pre>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/Form.hooks.tsx *\/  type IUseFormStateProps = {   \/** ...\u043d\u0443\u0436\u043d\u044b\u0435 props \u0434\u043b\u044f \u0445\u0443\u043a\u0430 *\/ }  \/** \u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0445\u0443\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b *\/ export const useFormState = ({ initialState = {} }: IUseFormStateProps) => {   const [state, setState] = useState(initialState)    const updateValues = useCallback(({name, value}: { name: string; value: any }) => {     setState(((prevState) => ({...prevState, ...{[name]: value}})))   }, []);    return {     state,     handlers: {       updateValues,     },   }; }; <\/code><\/pre>\n<p>\u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:<\/p>\n<pre><code class=\"typescript\">\/** src\/App.tsx *\/  function App() {   const { state, handlers } = useFormState({});    return (     &lt;div className=\"App\">       &lt;Form>         &lt;Input           name=\"username\"           value={state.username}           onChange={(value) =>             handlers.updateValues({ name: \"username\", value })           }         \/>         &lt;Input           name=\"password\"           value={state.password}           onChange={(value) =>             handlers.updateValues({ name: \"password\", value })           }         \/>         &lt;Select           name={\"gender\"}           list={[...]}           value={state.gender}           onChange={(value) => handlers.updateValues({ name: \"gender\", value })}         \/>       &lt;\/Form>     &lt;\/div>   ); }  export default App; <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u0435\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043f\u043e\u0434\u0441\u0432\u0435\u0447\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043d\u0435\u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043d\u043e \u0440\u0430\u0437\u0434\u0443\u043b\u0438\u0441\u044c \u043d\u0430\u0448\u0438 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u0432 \u0442\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0433\u0434\u0435 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 value \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a onChange. \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0448\u0435\u0439 \u0444\u043e\u0440\u043c\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0440\u0443\u043a\u0430\u043c\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u0442\u044c \u0435\u0433\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 value, \u0430 \u043a\u0430\u043a\u043e\u0439 \u0443 \u043d\u0435\u0433\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c onChange? \u0410 \u043e\u0431\u0449\u0438\u0435 \u0441\u0442\u0438\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c, \u0432\u0434\u0440\u0443\u0433 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043d\u0438\u0445 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u0430\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430? \u0410 \u043a\u0430\u043a \u0436\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Don%E2%80%99t_repeat_yourself\" rel=\"noopener noreferrer nofollow\">DRY<\/a>, \u0442\u0443\u0442 \u044f\u0432\u043d\u043e \u0436\u0435 \u0438\u043c \u043d\u0435 \u043f\u0430\u0445\u043d\u0435\u0442 \u0434\u0430\u0436\u0435? \u0410 \u043a\u0430\u043a \u0436\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0438\u0434\u0435?<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044d\u0442\u043e \u0436\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430! \u041f\u0440\u043e\u0431\u043b\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445 onChange, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432 state \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435 value \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<p>\u041d\u0430\u0448 \u0434\u043e\u043b\u0433, \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f? \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u0441\u044e \u043e\u0431\u0449\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e \u0441\u0432\u044f\u0437\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b \u0438 \u0435\u0435 \u043f\u043e\u043b\u0435\u0439 (\u0438\u043d\u043f\u0443\u0442\u044b, \u0441\u0435\u043b\u0435\u043a\u0442\u044b, \u0447\u0435\u043a\u0431\u043e\u043a\u0441\u044b) \u0432 \u043e\u0434\u043d\u0443 \u043e\u0431\u0435\u0440\u0442\u043a\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f HOC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0444\u043e\u0440\u043c\u044b. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/Form.tsx *\/  \/**  *\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b React.Context,  *\u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e \u0434\u0430\u043d\u043d\u044b\u0445  *  \u043d\u0438\u0436\u0435 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432  *\/ type IFormContext = {   \/** ...\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0432\u0441\u0435-\u0432\u0441\u0435, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b *\/ };  export const FormContext = React.createContext&lt;IFormContext>({   state: {},   handlers: {     updateValues: () => console.error(\"not initialized\"),   }, });  type FormProps = {   formEntity: IFormContext;   children?: React.ReactNode;   \/** ... *\/ };  export const Form: React.FC&lt;FormProps> = ({   children,   formEntity,   ...restProps }) => {   \/**    * ...    *\/   return (     &lt;FormContext.Provider value={formEntity}>       &lt;form {...restProps}>{children}&lt;\/form>     &lt;\/FormContext.Provider>   ); }; <\/code><\/pre>\n<pre><code class=\"typescript\">\/** src\/components\/Form\/withFormState.tsx *\/  \/** \u041a\u0430\u043a \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e HOC'a *\/ export const withFormState = &lt;   T extends WithFormStateProps = WithFormStateProps >(   WrappedComponent: React.ComponentType&lt;T>,   name: string ) => {   const { state, handlers } = useContext(FormContext);   const value = state[name]?.value || null;    const hocComponent = ({ ...props }) => (     &lt;WrappedComponent {...props} name={name} value={value} \/>   );    return hocComponent; }; <\/code><\/pre>\n<p>\u0418 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p>\n<pre><code class=\"typescript\">\/** src\/App.tsx *\/  function App() {   const formEntity = useFormState({});    const UsernameField = withFormState(Input, \"name\");   const PasswordField = withFormState(Input, \"password\");   const GenderField = withFormState(Select, \"gender\");    return (     &lt;div className=\"App\">       &lt;Form formEntity={formEntity}>         &lt;UsernameField \/>         &lt;PasswordField \/>         &lt;GenderField \/>       &lt;\/Form>     &lt;\/div>   ); }  export default App; <\/code><\/pre>\n<p>\u041c-\u0434\u0430, \u0438\u0437\u044f\u0449\u0435\u0441\u0442\u0432\u0430 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043c\u0430\u043b\u043e\u0432\u0430\u0442\u043e. \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 HOC\u2019a \u0432 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0443\u0436\u0435 \u0441 \u043d\u0438\u043c.<\/p>\n<pre><code class=\"markdown\">\u251c\u2500\u2500 components\/ \u2502   \u251c\u2500\u2500 Form\/ \u2502   \u2502   \u251c\u2500\u2500 Form.hooks.ts \u2502   \u2502   \u2514\u2500\u2500 Form.tsx \u2502   \u251c\u2500\u2500 Input\/ \u2502   \u2502   \u251c\u2500\u2500 Input.tsx \u2502   \u2502   \u2514\u2500\u2500 ! EnhancedInput.tsx (\u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0441\u044e\u0434\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u043e\u0439 \u0438\u043d\u043f\u0443\u0442) \u2502   \u251c\u2500\u2500 Select\/ \u2502   \u2502   \u251c\u2500\u2500 Select.tsx \u2502   \u2502   \u2514\u2500\u2500 ! EnhancedSelect.tsx (\u0438 \u0441\u044e\u0434\u0430...) \u2502   \u2514\u2500\u2500 ...other components (\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435?) \u251c\u2500\u2500 App.tsx \u2514\u2500\u2500 index.ts <\/code><\/pre>\n<pre><code class=\"typescript\">\/** src\/components\/Input\/EnhancedInput.tsx *\/  type EnhancedInputProps = {   name: string; } &amp; InputProps;  \/** \u041a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u0438 Enchanced \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c *\/ export const EnhancedInput: React.FC&lt;EnhancedInputProps> = ({ name, ...restProps }) => {   const ResultComponent = withFormState(Input, name)        return &lt;ResultComponent {...restProps} \/>; }; <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438 \u043b\u0443\u0447\u0448\u0435, \u0442\u043e \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u0444\u043e\u0440\u043c\u044b? \u0418\u043d\u043f\u0443\u0442\u044b, \u0441\u0435\u043b\u0435\u043a\u0442\u044b, \u0447\u0435\u043a\u0431\u043e\u043a\u0441\u044b \u0443\u0436\u0435 \u0438 \u0442\u0430\u043a \u0435\u0441\u0442\u044c \u0432 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435, <strong>\u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043b\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/strong>!<\/p>\n<p>\u041c\u044b\u0441\u043b\u0438 \u0436\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0445\u0443\u043a\u043e\u0432 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0434\u0443\u0442 \u043d\u0430\u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0442\u0443\u043f\u0438\u043a. \u0422\u0430\u043a \u0436\u0435 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0440\u0435\u0434\u043a\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442<\/h3>\n<p>\u041f\u043e\u0434 react \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438, \u0430 \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u043e\u0439 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043c\u0438\u0440\u0435 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0422\u0430\u043a \u043a\u0430\u043a \u0436\u0435 \u0440\u0435\u0448\u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/ant.design\/\" rel=\"noopener noreferrer nofollow\">ant design<\/a>? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 (\u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <a href=\"https:\/\/ant.design\/components\/form\/\" rel=\"noopener noreferrer nofollow\">Form<\/a> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 antd:<\/p>\n<pre><code class=\"typescript\">import { Button, Checkbox, Form, Input } from 'antd'; import React from 'react';  const AntdExample: React.FC = () => {   const onFinish = (values: any) => {     console.log('Success:', values);   };    const onFinishFailed = (errorInfo: any) => {     console.log('Failed:', errorInfo);   };    return (     &lt;Form       onFinish={onFinish}       onFinishFailed={onFinishFailed}     >       &lt;Form.Item         label=\"Username\"         name=\"username\"       >         &lt;Input \/>       &lt;\/Form.Item>        &lt;Form.Item         label=\"Password\"         name=\"password\"       >         &lt;Input.Password \/>       &lt;\/Form.Item>        &lt;Form.Item name=\"remember\">         &lt;Checkbox>Remember me&lt;\/Checkbox>       &lt;\/Form.Item>        &lt;Form.Item>         &lt;Button type=\"primary\" htmlType=\"submit\">           Submit         &lt;\/Button>       &lt;\/Form.Item>     &lt;\/Form>   ); };  export default AntdExample; <\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u0438\u0437\u044f\u0449\u043d\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0433\u043b\u0430\u0437 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 value \u0438 onChange (<strong>\u0438 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435!<\/strong>) \u043a <\/p>\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-335592","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335592","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=335592"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335592\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}