{"id":400300,"date":"2024-06-29T15:10:31","date_gmt":"2024-06-29T15:10:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=400300"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=400300","title":{"rendered":"<span>React. \u0421\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0445\u0443\u043a\u0438: \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/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>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u042f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439 \u0444\u0443\u043b\u0441\u0442\u0435\u043a-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0438 \u044d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u0440\u0435\u0430\u043a\u0442\u0435 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p><strong>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435<\/strong>: \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b <\/p>\n<h3>\u041a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%B0%D1%80%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a> \u0441 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>f<\/em> \u043e\u0442 N \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>g<\/em> \u043e\u0442 M &lt;= N \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>w<\/em> \u043e\u0442 N &#8212; M \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/strong><\/p>\n<pre><code class=\"javascript\">function sum(first, second, third) {     return first + second + third; }  \/\/ \u043f\u0443\u0441\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f curry,  \/\/ \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0451 \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e const curriedSum = curry(sum);  \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a: const sum1 = curriedSum(10)(5)(20); const sum2 = curriedSum(10, 5)(20); const sum3 = curriedSum(10)(5, 20); const sum4 = curriedSum(10, 5, 20);  \/\/ \u0438 \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e sum1 === sum2 === sum3 === sum4 === 25<\/code><\/pre>\n<h3>\u0410 \u0447\u0442\u043e \u0441 \u0440\u0435\u0430\u043a\u0442\u043e\u043c?<\/h3>\n<p>\u041f\u0443\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:<\/p>\n<pre><code class=\"javascript\">function ExampleComponent({title, text}) {   return (     &lt;div>     &lt;p>{title}&lt;\/p>     &lt;p>{text}&lt;\/p>     &lt;\/div>   ) }  <\/code><\/pre>\n<p>\u0418 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u0430\u0437\u043e\u0432\u0451\u043c \u0445\u0443\u043a <em>useCurry<\/em>. <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u0445\u0443\u043a\u0430:<\/p>\n<ol>\n<li>\n<p>\u0425\u0443\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u0425\u0443\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043c\u0438\u043c\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u044b\u0445 \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435 \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0437\u0430\u043d\u043e\u0432\u043e \u043f\u0440\u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u043f\u0441\u043e\u0432<\/p>\n<\/li>\n<\/ol>\n<p>\u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 3 \u0438 4, \u0434\u0430\u043b\u044c\u0448\u0435 \u044f \u0431\u0443\u0434\u0443 \u0447\u0430\u0441\u0442\u043e \u043a \u043d\u0438\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0445\u0443\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">function ParentComponent() {   const CurriedEC = useCurry(ExampleComponent,                               {text: '\u042d\u0442\u043e \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442'}});      \/\/ \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 &lt;ExampleComponent text title \/>   return &lt;CurriedEC title=\"\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\" \/> }       <\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f useCurry<\/h3>\n<p><strong>\u041d\u0430\u0438\u0432\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/strong> <\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0443\u044e \u043f\u0435\u0440\u0432\u044b\u043c \u0442\u0440\u0451\u043c \u043f\u0443\u043d\u043a\u0442\u0430\u043c<\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const CurriedComponent = function(restProps) {       return &lt;ComponentToCurry {...props} {...restProps} \/>     };      return CurriedComponent; }  <\/code><\/pre>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, <em>useCurry<\/em> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u043e\u0432\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f. \u042d\u0442\u043e \u043f\u0440\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e 3, \u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0438 \u0442\u0430\u043a \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e &#8216;\u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c&#8217; \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <em>CurriedComponent<\/em>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432\u043d\u0443\u0442\u0440\u0438 <em>useCurry<\/em>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u0430\u043a\u0442 \u0437\u0430\u043d\u043e\u0432\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e. \u0415\u0441\u043b\u0438 \u044f \u043d\u0435 \u043e\u0448\u0438\u0431\u0430\u044e\u0441\u044c, \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u044b \u043a\u043b\u044e\u0447\u0438.<\/p>\n<p>\u041d\u043e \u043a\u0430\u043a \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e? <em>useCallback<\/em> \u0434\u043e\u043b\u0436\u0435\u043d \u0441 \u044d\u0442\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f, \u0434\u0430?<\/p>\n<p><strong>useCallback<\/strong>:<\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const CurriedComponent = useCallback((restProps) => {       return &lt;ComponentToCurry {... props} {... restProps} \/>     }, [props, ComponentToCurry]);      return CurriedComponent; }<\/code><\/pre>\n<p>\u0423 <em>useCallback<\/em> \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u043a\u0443\u0434\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438\u0441\u044c <em>props<\/em>.<br \/>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>props<\/em> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f <em>CurriedComponent<\/em>, \u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c!<br \/>\u041b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0440\u0430\u043d\u044c\u0448\u0435, \u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <em>useRef<\/em>. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 <em>useCallback<\/em>, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0444\u044b \u0441\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u043c\u043e\u0447\u044c. \u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c props \u0432 <em>useRef<\/em>, \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0444\u0430 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>props<\/em>, \u0434\u0430? <\/p>\n<p><strong>useRef:<\/strong><\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const propsRef = useRef(props);     useEffect(() => {         propsRef.current = props;     }, [props]);          const CurriedComponent = useCallback(         (restProps) => {             return &lt;ComponentToCurry {...propsRef.current}            {...restProps} \/>;         }, [ComponentToCurry]     );      return CurriedComponent; }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043a\u0440\u043e\u043c\u0435 <em>ComponentToCurry<\/em> \u043d\u0435\u0442, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e <em>CurriedComponent<\/em> \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 (\u043d\u0430 \u0441\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0445\u0443\u043a\u0430 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f <em>ComponentToCurry<\/em>, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0442\u043e\u0436\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f<em>)<\/em>. <\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u043a\u043e\u043d\u0435\u0446, \u0432\u0435\u0434\u044c \u0432 \u043f\u043e\u0433\u043e\u043d\u0435 \u0437\u0430 \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u044b\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0442\u0440\u0435\u0442\u044c\u0435! <em>useEffect<\/em>, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u0440\u0435\u0444, \u043d\u043e \u043d\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f <em>CurriedComponent, <\/em>\u0432\u0435\u0434\u044c<em> propsRef.current <\/em>\u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442<em> <\/em>\u0441<em> <\/em>\u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0447\u0438\u0441\u043b\u043e \u0435\u0433\u043e \u043f\u0440\u043e\u043f\u0441\u043e\u0432<\/p>\n<p>\u0417\u043d\u0430\u0447\u0438\u0442 \u043d\u0430\u0434\u043e <strong>\u0441\u0438\u043b\u043e\u0439<\/strong> \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c <em>CurriedComponent <\/em>\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>propsRef.current. <\/em>\u0410 \u0447\u0442\u043e \u0437\u0430 \u0441\u0438\u043b\u0430, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b. \u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432 \u0440\u0435\u0430\u043a\u0442\u0435 \u043d\u0430 \u0442\u0430\u043a\u043e\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430, \u0438, \u0443\u0432\u044b, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u042f \u0433\u043e\u0432\u043e\u0440\u044e \u043e <em>forceUpdate<\/em>, \u044d\u0442\u0443 \u0442\u0451\u043c\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e \u0435\u0449\u0451 \u043d\u0435 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p><strong>forceUpdate:<\/strong><\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const propsRef = useRef(props);   const curriedComponentRef = useRef(undefined);     useEffect(() => {         propsRef.current = props;       curriedComponentRef.current?.forceUpdate();     }, [props]);          const CurriedComponent = useMemo(() =>         class CurriedComponent extends React.Component {             constructor(restProps) {                 super(restProps);                 curriedComponentRef.current = this;             }              render() {                 return &lt;ComponentToCurry {...this.props}                {...curriedPropsRef.current} \/>;             }         },     [ComponentToCurry] );      return CurriedComponent; }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>propsRef<\/em> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f <em>forceUpdate<\/em>, \u0438 <em>CurriedComponent \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u0441\u044f. <br \/>useCallback \u0438\u0441\u0447\u0435\u0437, \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e useMemo<\/em><\/p>\n<p>\u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0433\u043e\u0442\u043e\u0432\u043e! <\/p>\n<h3>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043a\u043d\u0430.<br \/>\u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434: <\/p>\n<p><code>const [(d\/D)ialog, setOpen, (open)] = useDialog(...)<\/code><strong>,<\/p>\n<p><\/strong>\u0433\u0434\u0435 <em>(d\/D)ialog<\/em> \u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043b\u0438\u0431\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u043d\u0443\u0442\u0440\u044c <em>useDialog<\/em><strong> <\/strong>\u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u043f\u0441\u044b \u0434\u0438\u0430\u043b\u043e\u0433\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u043a\u0441\u0442) \u043f\u043e\u043c\u0438\u043c\u043e <em>open<\/em>, \u0430 \u0432\u043d\u0443\u0442\u0440\u0438<strong> <\/strong><em>useDialog<\/em> \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <em>Dialog<\/em>, \u0447\u0442\u043e \u0432\u0440\u044f\u0434 \u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c.<br \/>\u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">function useDialog(dialogProps) {   const [open, setOpen] = useState(false);   const dialog = useMemo(() => &lt;Dialog open={open} {...dialogProps} \/>,                           [dialogProps, open]);   return [dialog, setOpen]; }  function DialogWrapper() {   const [dialog, setOpen] = useDialog({text: '\u042d\u0442\u043e \u0434\u0438\u0430\u043b\u043e\u0433!'});   useEffect(() => {       setTimeout(() => setOpen(true), 3000);   }, []);   return dialog; }  <\/code><\/pre>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c <em>open<\/em> \u0432\u043d\u0443\u0442\u0440\u044c <em>Dialog<\/em>, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043c\u043e\u0433 \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <em>useDialog<\/em>:<\/p>\n<pre><code class=\"javascript\">function useDialog() {      const [open, setOpen] = useState(false);      return [Dialog, setOpen, open]; }    function DialogWrapper() {      const [Dialog, setOpen, open] = useDialog();      useEffect(() => {            setTimeout(() => setOpen(true), 3000);      }, []);      return &lt;Dialog text='\u042d\u0442\u043e \u0434\u0438\u0430\u043b\u043e\u0433' open={open} \/>; }  <\/code><\/pre>\n<p>\u0421 useCurry \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0431\u044b \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">function useDialog() {      const [open, setOpen] = useState(false);    const CurriedDialog = useCurry(Dialog, {open});   return [CurriedDialog, setOpen]; }    function DialogWrapper() {      const [Dialog, setOpen] = useDialog();      useEffect(() => {            setTimeout(() => setOpen(true), 3000);      }, []);      return &lt;Dialog text='\u042d\u0442\u043e \u0434\u0438\u0430\u043b\u043e\u0433'\/>; }  <\/code><\/pre>\n<p>\u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438.<br \/>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<br \/><code>&lt;Dialog text='\u041f\u0435\u0440\u0432\u044b\u0439 \u0434\u0438\u0430\u043b\u043e\u0433' \/> <br \/>&lt;Dialog text='\u0412\u0442\u043e\u0440\u043e\u0439 \u0434\u0438\u0430\u043b\u043e\u0433' \/><\/code><\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e useDialog \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0430 setOpen \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u0442 open, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 useDialog, \u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438<\/em><\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0415\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u0439\u0434\u0451\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u043a\u043b\u0438\u043a, \u0442\u043e \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u0445\u0443\u043a\u0430\u0445.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/593479\/\"> https:\/\/habr.com\/ru\/articles\/593479\/<\/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>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u042f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439 \u0444\u0443\u043b\u0441\u0442\u0435\u043a-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0438 \u044d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u0440\u0435\u0430\u043a\u0442\u0435 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p><strong>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435<\/strong>: \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b <\/p>\n<h3>\u041a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%B0%D1%80%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a> \u0441 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>f<\/em> \u043e\u0442 N \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>g<\/em> \u043e\u0442 M &lt;= N \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>w<\/em> \u043e\u0442 N &#8212; M \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/strong><\/p>\n<pre><code class=\"javascript\">function sum(first, second, third) {     return first + second + third; }  \/\/ \u043f\u0443\u0441\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f curry,  \/\/ \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0451 \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e const curriedSum = curry(sum);  \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a: const sum1 = curriedSum(10)(5)(20); const sum2 = curriedSum(10, 5)(20); const sum3 = curriedSum(10)(5, 20); const sum4 = curriedSum(10, 5, 20);  \/\/ \u0438 \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e sum1 === sum2 === sum3 === sum4 === 25<\/code><\/pre>\n<h3>\u0410 \u0447\u0442\u043e \u0441 \u0440\u0435\u0430\u043a\u0442\u043e\u043c?<\/h3>\n<p>\u041f\u0443\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:<\/p>\n<pre><code class=\"javascript\">function ExampleComponent({title, text}) {   return (     &lt;div>     &lt;p>{title}&lt;\/p>     &lt;p>{text}&lt;\/p>     &lt;\/div>   ) }  <\/code><\/pre>\n<p>\u0418 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u0430\u0437\u043e\u0432\u0451\u043c \u0445\u0443\u043a <em>useCurry<\/em>. <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u0445\u0443\u043a\u0430:<\/p>\n<ol>\n<li>\n<p>\u0425\u0443\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u0425\u0443\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043c\u0438\u043c\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u044b\u0445 \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435 \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0437\u0430\u043d\u043e\u0432\u043e \u043f\u0440\u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u043f\u0441\u043e\u0432<\/p>\n<\/li>\n<\/ol>\n<p>\u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 3 \u0438 4, \u0434\u0430\u043b\u044c\u0448\u0435 \u044f \u0431\u0443\u0434\u0443 \u0447\u0430\u0441\u0442\u043e \u043a \u043d\u0438\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0445\u0443\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">function ParentComponent() {   const CurriedEC = useCurry(ExampleComponent,                               {text: '\u042d\u0442\u043e \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442'}});      \/\/ \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 &lt;ExampleComponent text title \/>   return &lt;CurriedEC title=\"\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\" \/> }       <\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f useCurry<\/h3>\n<p><strong>\u041d\u0430\u0438\u0432\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/strong> <\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0443\u044e \u043f\u0435\u0440\u0432\u044b\u043c \u0442\u0440\u0451\u043c \u043f\u0443\u043d\u043a\u0442\u0430\u043c<\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const CurriedComponent = function(restProps) {       return &lt;ComponentToCurry {...props} {...restProps} \/>     };      return CurriedComponent; }  <\/code><\/pre>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, <em>useCurry<\/em> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u043e\u0432\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f. \u042d\u0442\u043e \u043f\u0440\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e 3, \u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0438 \u0442\u0430\u043a \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e &#8216;\u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c&#8217; \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <em>CurriedComponent<\/em>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432\u043d\u0443\u0442\u0440\u0438 <em>useCurry<\/em>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u0430\u043a\u0442 \u0437\u0430\u043d\u043e\u0432\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e. \u0415\u0441\u043b\u0438 \u044f \u043d\u0435 \u043e\u0448\u0438\u0431\u0430\u044e\u0441\u044c, \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u044b \u043a\u043b\u044e\u0447\u0438.<\/p>\n<p>\u041d\u043e \u043a\u0430\u043a \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e? <em>useCallback<\/em> \u0434\u043e\u043b\u0436\u0435\u043d \u0441 \u044d\u0442\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f, \u0434\u0430?<\/p>\n<p><strong>useCallback<\/strong>:<\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const CurriedComponent = useCallback((restProps) => {       return &lt;ComponentToCurry {... props} {... restProps} \/>     }, [props, ComponentToCurry]);      return CurriedComponent; }<\/code><\/pre>\n<p>\u0423 <em>useCallback<\/em> \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u043a\u0443\u0434\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438\u0441\u044c <em>props<\/em>.<br \/>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>props<\/em> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f <em>CurriedComponent<\/em>, \u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c!<br \/>\u041b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0440\u0430\u043d\u044c\u0448\u0435, \u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <em>useRef<\/em>. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 <em>useCallback<\/em>, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0444\u044b \u0441\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u043c\u043e\u0447\u044c. \u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c props \u0432 <em>useRef<\/em>, \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0444\u0430 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>props<\/em>, \u0434\u0430? <\/p>\n<p><strong>useRef:<\/strong><\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const propsRef = useRef(props);     useEffect(() => {         propsRef.current = props;     }, [props]);          const CurriedComponent = useCallback(         (restProps) => {             return &lt;ComponentToCurry {...propsRef.current}            {...restProps} \/>;         }, [ComponentToCurry]     );      return CurriedComponent; }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043a\u0440\u043e\u043c\u0435 <em>ComponentToCurry<\/em> \u043d\u0435\u0442, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e <em>CurriedComponent<\/em> \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 (\u043d\u0430 \u0441\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0445\u0443\u043a\u0430 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f <em>ComponentToCurry<\/em>, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0442\u043e\u0436\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f<em>)<\/em>. <\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u043a\u043e\u043d\u0435\u0446, \u0432\u0435\u0434\u044c \u0432 \u043f\u043e\u0433\u043e\u043d\u0435 \u0437\u0430 \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u044b\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0442\u0440\u0435\u0442\u044c\u0435! <em>useEffect<\/em>, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u0440\u0435\u0444, \u043d\u043e \u043d\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f <em>CurriedComponent, <\/em>\u0432\u0435\u0434\u044c<em> propsRef.current <\/em>\u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442<em> <\/em>\u0441<em> <\/em>\u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0447\u0438\u0441\u043b\u043e \u0435\u0433\u043e \u043f\u0440\u043e\u043f\u0441\u043e\u0432<\/p>\n<p>\u0417\u043d\u0430\u0447\u0438\u0442 \u043d\u0430\u0434\u043e <strong>\u0441\u0438\u043b\u043e\u0439<\/strong> \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c <em>CurriedComponent <\/em>\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>propsRef.current. <\/em>\u0410 \u0447\u0442\u043e \u0437\u0430 \u0441\u0438\u043b\u0430, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b. \u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432 \u0440\u0435\u0430\u043a\u0442\u0435 \u043d\u0430 \u0442\u0430\u043a\u043e\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430, \u0438, \u0443\u0432\u044b, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u042f \u0433\u043e\u0432\u043e\u0440\u044e \u043e <em>forceUpdate<\/em>, \u044d\u0442\u0443 \u0442\u0451\u043c\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e \u0435\u0449\u0451 \u043d\u0435 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p><strong>forceUpdate:<\/strong><\/p>\n<pre><code class=\"javascript\">function useCurry(ComponentToCurry, props) {     const propsRef = useRef(props);   const curriedComponentRef = useRef(undefined);     useEffect(() => {         propsRef.current = props;       curriedComponentRef.current?.forceUpdate();     }, [props]);          const CurriedComponent = useMemo(() =>         class CurriedComponent extends React.Component {             constructor(restProps) {                 super(restProps);                 curriedComponentRef.current = this;             }              render() {                 return &lt;ComponentToCurry {...this.props}                {...curriedPropsRef.current} \/>;             }         },     [ComponentToCurry] );      return CurriedComponent; }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <em>propsRef<\/em> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f <em>forceUpdate<\/em>, \u0438 <em>CurriedComponent \u043f\u0435\u0440\u0435\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u0441\u044f. <br \/>useCallback \u0438\u0441\u0447\u0435\u0437, \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e useMemo<\/em><\/p>\n<p>\u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0433\u043e\u0442\u043e\u0432\u043e! <\/p>\n<h3>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043a\u043d\u0430.<br \/>\u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434: <\/p>\n<p><code>const [(d\/D)ialog, setOpen, (open)] = useDialog(...)<\/code><strong>,<\/p>\n<p><\/strong>\u0433\u0434\u0435 <em>(d\/D)ialog<\/em> \u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043b\u0438\u0431\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u043d\u0443\u0442\u0440\u044c <em>useDialog<\/em><strong> <\/strong>\u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u043f\u0441\u044b \u0434\u0438\u0430\u043b\u043e\u0433\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u043a\u0441\u0442) \u043f\u043e\u043c\u0438\u043c\u043e <em>open<\/em>, \u0430 \u0432\u043d\u0443\u0442\u0440\u0438<strong> <\/strong><em>useDialog<\/em> \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <em>Dialog<\/em>, \u0447\u0442\u043e \u0432\u0440\u044f\u0434 \u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c.<br \/>\u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">function useDialog(dialogProps) {   const [open, setOpen] = useState(false);   const dialog = useMemo(() => &lt;Dialog open={open} {...dialogProps} \/>,                           [dialogProps, open]);   return [dialog, setOpen]; }  function DialogWrapper() {   const [dialog, setOpen] = useDialog({text: '\u042d\u0442\u043e \u0434\u0438\u0430\u043b\u043e\u0433!'});   useEffect(() => {       setTimeout(() => setOpen(true), 3000);   }, []);   return dialog; }  <\/code><\/pre>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c <em>open<\/em> \u0432\u043d\u0443\u0442\u0440\u044c <em>Dialog<\/em>, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043c\u043e\u0433 \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <em>useDialog<\/em>:<\/p>\n<pre><code class=\"javascript\">function useDialog() {      const [open, setOpen] = useState(false);      return [Dialog, setOpen, open]; }    function DialogWrapper() {      const [Dialog, setOpen, open] = useDialog();      useEffect(() => {            setTimeout(() => setOpen(true), 3000);      }, []);      return &lt;Dialog text='\u042d\u0442\u043e \u0434\u0438\u0430\u043b\u043e\u0433' open={open} \/>; }  <\/code><\/pre>\n<p>\u0421 useCurry \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0431\u044b \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">function useDialog() {      const [open, setOpen] = useState(false);    const CurriedDialog = useCurry(Dialog, {open});   return [CurriedDialog, setOpen]; }    function DialogWrapper() {      const [Dialog, setOpen] = useDialog();      useEffect(() => {            setTimeout(() => setOpen(true), 3000);      }, []);      return &lt;Dialog text='\u042d\u0442\u043e \u0434\u0438\u0430\u043b\u043e\u0433'\/>; }  <\/code><\/pre>\n<p>\u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438.<br \/>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<br \/><code>&lt;Dialog text='\u041f\u0435\u0440\u0432\u044b\u0439 \u0434\u0438\u0430\u043b\u043e\u0433' \/> <br \/>&lt;Dialog text='\u0412\u0442\u043e\u0440\u043e\u0439 \u0434\u0438\u0430\u043b\u043e\u0433' \/><\/code><\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e useDialog \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0430 setOpen \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u0442 open, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 useDialog, \u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438<\/em><\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0415\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u0439\u0434\u0451\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u043a\u043b\u0438\u043a, \u0442\u043e \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u0445\u0443\u043a\u0430\u0445.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/593479\/\"> https:\/\/habr.com\/ru\/articles\/593479\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-400300","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/400300","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=400300"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/400300\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=400300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=400300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=400300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}