{"id":971,"date":"2026-01-31T12:27:30","date_gmt":"2026-01-31T12:27:30","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=971"},"modified":"2026-01-31T12:27:32","modified_gmt":"2026-01-31T12:27:32","slug":"%d1%87%d1%82%d0%be-%d1%82%d0%b0%d0%ba%d0%be%d0%b5-state-hoisting-%d0%bf%d0%be%d1%87%d0%b5%d0%bc%d1%83-%d1%8d%d1%82%d0%be-%d0%ba%d0%bb%d1%8e%d1%87%d0%b5%d0%b2%d0%b0%d1%8f-%d0%bf%d1%80%d0%b0%d0%ba","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=971","title":{"rendered":"\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 State Hoisting? \u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0432 Compose?"},"content":{"rendered":"\n<p>State hoisting \u0432 Compose \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e <strong>\u043f\u043e\u0434\u043d\u044f\u0442\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043d\u0430\u0432\u0435\u0440\u0445 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443<\/strong>, \u0438\u0437 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e <code>@Composable<\/code> \u0432 \u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f.<\/p>\n\n\n\n<p>\u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 state, \u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0435\u0433\u043e &#171;\u0441\u0432\u0435\u0440\u0445\u0443&#187; \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 &#171;\u043d\u0430\u0432\u0435\u0440\u0445&#187;.<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>\u0418 \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a \u0432 Compose, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 <strong>\u043e\u0434\u0438\u043d \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u0441\u0442\u0438\u043d\u044b, \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c UI.<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 State Hoisting \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/h4>\n\n\n\n<p><strong>\u041f\u043b\u043e\u0445\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0435\u0437 hoisting-\u0430 \u2014 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0430\u043c \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@Composable\nfun Counter() {\n    var count by remember { mutableStateOf(0) }\n\n    Button(onClick = { count++ }) {\n        Text(&quot;Count = $count&quot;)\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u0417\u0434\u0435\u0441\u044c <code>Counter<\/code> <strong>\u0441\u0430\u043c \u0445\u0440\u0430\u043d\u0438\u0442<\/strong> \u0441\u0432\u043e\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c <strong>\u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong> <code>count<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0435\u0433\u043e,<\/li>\n\n\n\n<li>\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435,<\/li>\n\n\n\n<li>\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u0442\u0435\u0439\u0442\u043e\u043c.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Hoisted state \u2014 \u0432\u044b\u043d\u043e\u0441\u0438\u043c state \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@Composable\nfun Counter(\n    count: Int,\n    onIncrement: () -&gt; Unit\n) {\n    Button(onClick = onIncrement) {\n        Text(&quot;Count = $count&quot;)\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u0410 \u0441\u0442\u0435\u0439\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0445\u0440\u0430\u043d\u0438\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@Composable\nfun CounterScreen() {\n    var count by remember { mutableStateOf(0) }\n\n    Counter(\n        count = count,\n        onIncrement = { count++ }\n    )\n}\n<\/pre><\/div>\n\n\n<p><strong>\u0412\u043e\u0442 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c state hoisting:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>count<\/code> <strong>\u043f\u043e\u0434\u043d\u044f\u0442\u043e<\/strong> \u0438\u0437 <code>Counter<\/code> \u0432 <code>CounterScreen<\/code><\/li>\n\n\n\n<li><code>Counter<\/code> \u0441\u0442\u0430\u043b <strong>stateless<\/strong> (\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u0438\u0437\u0432\u043d\u0435)<\/li>\n\n\n\n<li>\u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e <strong>\u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442<\/strong> <code>count<\/code> \u0438 <strong>\u0440\u0435\u043f\u043e\u0440\u0442\u0438\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f<\/strong> \u0447\u0435\u0440\u0435\u0437 callback<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0432 Compose<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u041e\u0434\u0438\u043d \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u0441\u0442\u0438\u043d\u044b (Single Source of Truth)<\/li>\n\n\n\n<li>\u041b\u0451\u0433\u043a\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/li>\n\n\n\n<li>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c<\/li>\n\n\n\n<li>\u0423\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u201cstate down, events up\u201d<br><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 state \u043d\u0435 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c?<\/h4>\n\n\n\n<p>\u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043d\u0430\u0440\u0443\u0436\u0438 (\u043a\u0430\u043a <code>TextView<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043a\u0430\u0437\u0430\u0442\u044c: \u201c\u043d\u0435 \u043c\u0435\u043d\u044f\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441\u0430\u043c\u201d)<\/li>\n\n\n\n<li>state \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445<\/li>\n\n\n\n<li>\u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c: \u201c\u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435?\u201d<\/li>\n\n\n\n<li>\u0442\u0440\u0443\u0434\u043d\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a <code>ViewModel<\/code>\/<code>Flow<\/code> \u2014 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043b\u0435\u043f\u0438\u0442\u044c \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0432\u043d\u0438\u0437\u0443<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>State hoisting \u0432 Compose \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u043d\u044f\u0442\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043d\u0430\u0432\u0435\u0440\u0445 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443, \u0438\u0437 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e @Composable \u0432 \u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f. \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 state, \u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0435\u0433\u043e &#171;\u0441\u0432\u0435\u0440\u0445\u0443&#187; \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 &#171;\u043d\u0430\u0432\u0435\u0440\u0445&#187;. \u0418 \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a \u0432 Compose, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u0441\u0442\u0438\u043d\u044b, \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c UI. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-971","post","type-post","status-publish","format-standard","hentry","category-compose"],"_links":{"self":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=971"}],"version-history":[{"count":1,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/971\/revisions"}],"predecessor-version":[{"id":972,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/971\/revisions\/972"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}