{"id":288674,"date":"2018-08-29T13:00:03","date_gmt":"2018-08-29T09:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288674"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288674","title":{"rendered":"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f prevProps \u0432 getDerivedStateFromProps"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/421615\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<br \/>  \u0418\u0442\u0430\u043a, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0420\u0435\u0430\u043a\u0442\u0430 \u0440\u0435\u0448\u0438\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0438\u0445 \u043b\u0438\u0431\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439, \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043d\u0430\u0441 \u043d\u0435\u0440\u0430\u0434\u0438\u0432\u044b\u0445 \u043d\u0430 \u043f\u0443\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0448\u0430\u043d\u0441\u0430 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434, \u0447\u0442\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0448\u0438\u043c \u043d\u0435\u043e\u0442\u044a\u0435\u043c\u043b\u0435\u043c\u044b\u043c \u043f\u0440\u0430\u0432\u043e\u043c \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c. \u0420\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0432\u0441\u0435\u043c\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 componentWillReceiveProps \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u0437 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0435\u0440\u0438\u0438, \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u043d\u043e \u043d\u0430\u043c \u0434\u0430\u0434\u0443\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 getDerivedStateFromProps. \u041b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u043e\u043d \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0442\u0435\u043c\u043d\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0433\u0434\u0435 \u043b\u0435\u0436\u0430\u0442 \u0432\u0435\u0449\u0438, \u0438 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u043d\u043e. <\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043e\u0442\u0432\u0435\u0442\u0430\u0445 \u043d\u0430 \u0433\u043d\u0435\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0420\u0435\u0430\u043a\u0442\u0430 \u043f\u0438\u0448\u0443\u0442 \u043c\u043e\u043b: \u041d\u0443 \u043d\u0435 \u0434\u0430\u0434\u0438\u043c \u043c\u044b \u0432\u0430\u043c prevProps, \u044d\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0439\u0442\u0435 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c, prevProps \u043d\u0435\u0442, \u043d\u0443 \u0432\u044b \u0434\u0435\u0440\u0436\u0438\u0442\u0435\u0441\u044c \u0442\u0430\u043c, \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0435\u0448\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u0445 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0432 \u043e\u0431\u0449\u0435\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u0441\u0442\u044b\u043b\u0435\u043a \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u043e\u0432\u043e\u043c \u0445\u043e\u0440\u043e\u0448\u0435\u043c \u043a\u043e\u0434\u0435. \u042d\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0438 \u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c, \u043d\u043e \u0432\u043e\u0442 \u043c\u0435\u043d\u044f \u0440\u0430\u0437\u0434\u043e\u0441\u0430\u0434\u043e\u0432\u0430\u043b \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 this, \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u043c\u043e\u044e \u0437\u0430\u043c\u0443\u0440\u043e\u0432\u0430\u043b\u0438, \u0438\u0437 \u043d\u0435\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u043d\u043e, \u0434\u0430\u0436\u0435 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043d\u0435 \u0441\u043b\u044b\u0448\u043d\u043e, \u0432\u043e\u0442 \u0438 \u0440\u0435\u0448\u0438\u043b \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0448\u0442\u0443\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043a\u0440\u043e\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0441\u0435 \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0438 \u043c\u043e\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441 \u0432\u0438\u0434\u0443 \u0445\u043e\u0442\u044c \u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c, \u043d\u043e \u0431\u0435\u0441\u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u043c (\u0430 \u0431\u0435\u0441\u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u043c \u043b\u0438?).<\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c prevProps \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0435\u0449\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0436\u0438\u0442\u044c \u0431\u0435\u0437 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u043e\u0433\u043e this \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c getDerivedStateFromProps (\u0432\u043e\u0442 \u0434\u0443\u0440\u0430\u043a!). \u0414\u0432\u0430 \u0434\u043d\u044f \u043c\u0443\u0447\u0435\u043d\u0438\u0439 \u0438 \u0441\u0430\u043c\u043e\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u044f \u0440\u043e\u0434\u0438\u043b \u043c\u044b\u0448\u044c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"ustanovka\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h2>\n<p>  <\/p>\n<pre><code>npm install --save state-master<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"ispolzovanie\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 getDerivedStateFromProps \u0438 componentDidUpdate, \u043d\u043e \u0443\u0436\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435.<br \/>  \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 &#171;withStateMaster&#187;, \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u043f\u0438\u0441\u043e\u043a &#171;\u043f\u0440\u043e\u043f\u0441\u043e\u0432&#187;, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import {Component} from 'react' import {withStateMaster, registerContext, unregisterContext} from 'state-master';  \/\/ \u0421\u043f\u0438\u0441\u043e\u043a \"\u043f\u0440\u043e\u043f\u0441\u043e\u0432\", \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c const PROP_LIST = ['width', 'height', 'bgColor', 'fontSize', 'autoSize']; \/\/ \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 const PROP_LIST = 'value';  \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e const INITIAL_STATE = {   width: 1000,   height: 500 };  class ContainerComponent extends Component {   static displayName = 'Container';    static getDerivedStateFromProps(data) {     const {         nextProps,         prevProps,         state,         isInitial,         changed,         changedProps,         isChanged,         add,         addIfChanged,         isChangedAny,         addIfChangedAny,         isChangedAll,         call,         get       } = data;        \/\/ \u043d\u0438\u0436\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u0440\u043e\u043f\u0441\u0430\u0445, \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 PROPS_LIST       \/\/ \u043c\u0435\u0442\u043a\u0430 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430       if (isInitial) {         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u0435 \"name\" \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \"value\" \u043a \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f         add('name', value);         \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u0435 \"name\" \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u0437\u044f\u0442\u044b\u043c \u0438\u0437 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0445 \u043f\u0440\u043e\u043f\u0441\u043e\u0432         add('name');               }        \/\/ changedProps \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u043f\u043e\u043c\u0435\u043d\u044f\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u0440\u043e\u043f\u0441\u043e\u0432       if (changedProps.indexOf('value') !== -1) {         add('value');        }        \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 prop \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f       if (isChanged('autoSize')) {         add('autoSize');       }             \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 prop \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0437\u0434\u0435\u0441\u044c \u043d\u0430 true)       if (isChanged('autoSize', true)) {         add('autoSize', true);       }        \/\/ changed \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f true, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f       if (changed) {         add('somethingChanged', true);       }        \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f       \/\/ \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435       if (isChangedAny()) {          add('somethingChanged', true);       }        \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f       if (isChangedAny('bgColor', 'fontSize', ...)) {         const {bgColor, fontSize} = nextProps;         add('style', {bgColor, fontSize});       }        \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u043f\u0441\u044b \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 PROPS_LIST \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c       if (isChangedAll()) {         add('allChanged', true);       }        \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u043f\u0441\u043e\u0432 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c       if (isChangedAll('width', 'height', ...)) {         const {width, height} = nextProps;         add('size', width + 'x' + height);          \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c         \/\/ \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 setTimeout(() =&gt; this.changeSomething(), 0);         \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0434\u043b\u044f \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0430\u043f\u0434\u0435\u0439\u0442\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430         \/\/ \u0445\u043e\u0442\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u0432 componentDidUpdate         call(() =&gt; {           this.initNewSizes(width, height);         });       }        \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \"add\", \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 prop \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f       addIfChanged('name', value);       addIfChanged('name');        \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \"add\", \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e prop \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 PROPS_LIST \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f       addIfChangedAny('name', value);       addIfChangedAny('name');        \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u043b\u0438 null       \/\/ \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0443\u0448\u043b\u043e \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435       \/\/ \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0439\u0442\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435       console.log(get());        \/\/ \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \"add\", \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e       \/\/ \u0438\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u0430\u043a \u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \"add\"       return {         size: nextProps.width + 'x' + nextProps.height       }   }    constructor(props) {     super(props);     \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \"registerContext\", \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c this \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 getDerivedStateFromProps     \/\/ \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d \"registerContext\", \u0442\u043e \u0437\u0434\u0435\u0441\u044c \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e     registerContext(this);   }    \/\/ \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d   componentDidUpdate(data) {     const {         prevProps,         prevState,         snapshot,         changedProps,         changed,         isChanged,         isChangedAny,         isChangedAll       } = data;        if (isChanged('value')) {         const {value} = this.props;         this.doSomeAction(value);       }   }    componentWillUnmount() {     \/\/ \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0435\u0441\u043b\u0438 \"registerContext\" \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435     unregisterContext(this);   }    render() {     const {style, size} = this.state;     return (       &lt;div className=\"container\" style={style}&gt;         Size is {size}       &lt;\/div&gt;     )   } }  export const Container = withStateMaster(ContainerComponent, PROP_LIST, INITIAL_STATE);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e, \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 getDerivedStateFromProps \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export const Container = withStateMaster(ContainerComponent, PROP_LIST, null, ParentalComponent);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0433\u043e \u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b (\u0445\u043e\u0442\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043d\u044f\u043b \u0440\u0435\u0430\u043a\u0442, \u0438 \u044d\u0442\u043e \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430)<br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044f \u0432\u0441\u0442\u0443\u043f\u0438\u043b \u0432 \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u043c \u043a\u0430\u043d\u043e\u043d\u0430\u043c \u0420\u0435\u0430\u043a\u0442\u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u044f \u0441\u043c\u0438\u0440\u044e\u0441\u044c \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0443 \u0432\u0441\u0435 \u043a\u0430\u043a \u043d\u0430\u0434\u043e.<br \/>  \u0425\u043e\u0442\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u043f\u044f\u0442\u044c \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u044e\u0442 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0430\u0441\u0443\u0449\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<br \/>  \u0412\u0441\u0451, \u044f \u043b\u043e\u0436\u0443\u0441\u044c, \u0430 \u043b\u0435\u0436\u0430\u0447\u0438\u0445, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u043d\u0435 \u0431\u044c\u044e\u0442))<\/p>\n<p><\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/post\/421615\/\"> https:\/\/habr.com\/post\/421615\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/421615\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<br \/>  \u0418\u0442\u0430\u043a, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0420\u0435\u0430\u043a\u0442\u0430 \u0440\u0435\u0448\u0438\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0438\u0445 \u043b\u0438\u0431\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439, \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043d\u0430\u0441 \u043d\u0435\u0440\u0430\u0434\u0438\u0432\u044b\u0445 \u043d\u0430 \u043f\u0443\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0448\u0430\u043d\u0441\u0430 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434, \u0447\u0442\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0448\u0438\u043c \u043d\u0435\u043e\u0442\u044a\u0435\u043c\u043b\u0435\u043c\u044b\u043c \u043f\u0440\u0430\u0432\u043e\u043c \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c. \u0420\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0432\u0441\u0435\u043c\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 componentWillReceiveProps \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u0437 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0435\u0440\u0438\u0438, \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u043d\u043e \u043d\u0430\u043c \u0434\u0430\u0434\u0443\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 getDerivedStateFromProps. \u041b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u043e\u043d \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0442\u0435\u043c\u043d\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0433\u0434\u0435 \u043b\u0435\u0436\u0430\u0442 \u0432\u0435\u0449\u0438, \u0438 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u043d\u043e. <\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043e\u0442\u0432\u0435\u0442\u0430\u0445 \u043d\u0430 \u0433\u043d\u0435\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0420\u0435\u0430\u043a\u0442\u0430 \u043f\u0438\u0448\u0443\u0442 \u043c\u043e\u043b: \u041d\u0443 \u043d\u0435 \u0434\u0430\u0434\u0438\u043c \u043c\u044b \u0432\u0430\u043c prevProps, \u044d\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0439\u0442\u0435 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c, prevProps \u043d\u0435\u0442, \u043d\u0443 \u0432\u044b \u0434\u0435\u0440\u0436\u0438\u0442\u0435\u0441\u044c \u0442\u0430\u043c, \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0435\u0448\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u0445 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0432 \u043e\u0431\u0449\u0435\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u0441\u0442\u044b\u043b\u0435\u043a \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u043e\u0432\u043e\u043c \u0445\u043e\u0440\u043e\u0448\u0435\u043c \u043a\u043e\u0434\u0435. \u042d\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0438 \u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c, \u043d\u043e \u0432\u043e\u0442 \u043c\u0435\u043d\u044f \u0440\u0430\u0437\u0434\u043e\u0441\u0430\u0434\u043e\u0432\u0430\u043b \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 this, \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u043c\u043e\u044e \u0437\u0430\u043c\u0443\u0440\u043e\u0432\u0430\u043b\u0438, \u0438\u0437 \u043d\u0435\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u043d\u043e, \u0434\u0430\u0436\u0435 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043d\u0435 \u0441\u043b\u044b\u0448\u043d\u043e, \u0432\u043e\u0442 \u0438 \u0440\u0435\u0448\u0438\u043b \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0448\u0442\u0443\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043a\u0440\u043e\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0441\u0435 \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0438 \u043c\u043e\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441 \u0432\u0438\u0434\u0443 \u0445\u043e\u0442\u044c \u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c, \u043d\u043e \u0431\u0435\u0441\u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u043c (\u0430 \u0431\u0435\u0441\u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u043c \u043b\u0438?).<\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c prevProps \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0435\u0449\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0436\u0438\u0442\u044c \u0431\u0435\u0437 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u043e\u0433\u043e this \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c getDerivedStateFromProps (\u0432\u043e\u0442 \u0434\u0443\u0440\u0430\u043a!). \u0414\u0432\u0430 \u0434\u043d\u044f \u043c\u0443\u0447\u0435\u043d\u0438\u0439 \u0438 \u0441\u0430\u043c\u043e\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u044f \u0440\u043e\u0434\u0438\u043b \u043c\u044b\u0448\u044c.<\/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-288674","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288674","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=288674"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288674\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}