{"id":343426,"date":"2023-01-01T15:00:14","date_gmt":"2023-01-01T15:00:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343426"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343426","title":{"rendered":"<span>\u042d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c React useState \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c JS (via data-attributes &amp; css selectors)<\/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, \u0425\u0430\u0431\u0440! \u0420\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0432 \u043f\u043b\u0430\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f html data-attributes &amp; css selectors. <\/p>\n<p>Html data-attributes &#8212; \u044d\u0442\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043a\u0443\u0434\u0430-\u0443\u0433\u043e\u0434\u043d\u043e \u0438 \u0441 \u043a\u0430\u043a\u0438\u043c \u0443\u0433\u043e\u0434\u043d\u043e \u0438\u043c\u0435\u043d\u0435\u043c (\u043d\u043e \u0438\u043c\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 <code>data-<\/code>). \u0417\u0430\u0442\u0435\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 css \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u0445, \u0447\u0442\u043e\u0431\u044b \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0443\u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u0414\u0432\u0438\u0436\u043e\u043a \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 data-\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 css \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u041a\u043e\u0434 \u0440\u0435\u0430\u043a\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043a\u043d\u043e\u043f\u043a\u0438 \u0447\u0442\u043e-\u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"typescript\">import React, {useState} from \"react\";  const ComponentWithExpandableContent = () => {     const [expanded, setExpanded] = useState(false)      return &lt;div style={{         display: 'flex',         flexFlow: 'column nowrap',         alignItems: 'start',         padding: 32,         gap: 32,     }}>          { !expanded &amp;&amp; &lt;div>Initial content&lt;\/div> }          &lt;button onClick={()=>setExpanded(!expanded)}>             { !expanded ? 'Expand' : 'Collapse' }         &lt;\/button>          { expanded &amp;&amp; &lt;div>Additional content&lt;\/div> }         { expanded &amp;&amp; &lt;div>More additional content&lt;\/div> }      &lt;\/div> } export default React.memo(ComponentWithExpandableContent)<\/code><\/pre>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>expanded=false<\/code>:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b58\/7cc\/a7c\/b587cca7c9b3e981e5c479520af799c6.png\" width=\"179\" height=\"157\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b58\/7cc\/a7c\/b587cca7c9b3e981e5c479520af799c6.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>expanded=true<\/code>:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b21\/45f\/b54\/b2145fb54761e4b1224679e01541399e.png\" width=\"250\" height=\"200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b21\/45f\/b54\/b2145fb54761e4b1224679e01541399e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e <code>html css js<\/code>.<\/p>\n<p>\u0424\u0430\u0439\u043b <code>emulating-use-state.html:<\/code><\/p>\n<pre><code class=\"xml\">&lt;!DOCTYPE html> &lt;html lang=\"en\"> &lt;head>   &lt;meta charset=\"UTF-8\">   &lt;title>     \u042d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c React useState \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c JS      (via data-attributes &amp; css selectors)   &lt;\/title>   &lt;link rel=\"stylesheet\" type=\"text\/css\" href=\"emulating-use-state.css\"> &lt;\/head> &lt;body>  &lt;script>   function toggleExpand(){     const element = document.getElementById('component')     if (element.dataset.expanded!=='true'){       element.dataset.expanded = 'true'     } else {       element.dataset.expanded = 'false'     }   } &lt;\/script>  &lt;div class=\"someElementContext\">   &lt;!-- data-expanded \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 -->   &lt;div id=\"component\" class=\"component\" data-expanded=\"false\">          &lt;div class=\"collapsableContent\">       &lt;div>Initial content&lt;\/div>     &lt;\/div>          &lt;button onClick=\"toggleExpand()\">       &lt;div class=\"collapsableContent\">Expand&lt;\/div>       &lt;div class=\"expandableContent\">Collapse&lt;\/div>     &lt;\/button>        &lt;div class=\"expandableContent\">       &lt;div>Additional content&lt;\/div>     &lt;\/div>     &lt;div class=\"expandableContent\">       &lt;div>More additional content&lt;\/div>     &lt;\/div>        &lt;\/div> &lt;\/div>  &lt;\/body> &lt;\/html><\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b \u0441\u0442\u0438\u043b\u0435\u0439 <code>emulating-use-state.scss:<\/code><\/p>\n<pre><code class=\"css\">.someElementContext {   display: contents;      .component {     display: flex;     flex-flow: column nowrap;     align-items: start;     padding: 32px;     gap: 32px;          \/\/ \u041a\u043b\u0430\u0441\u0441\u044b, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435     \/\/ \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f data-expanded     .expandableContent {       display: none;     }     .collapsableContent {       display: contents;     }     &amp;[data-expanded=true] .expandableContent {       display: contents;     }     &amp;[data-expanded=true] .collapsableContent {       display: none;     }   } }<\/code><\/pre>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0440\u0435\u0434\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <code>emulating-use-state.css:<\/code> <\/p>\n<pre><code class=\"css\">.someElementContext {   display: contents; } .someElementContext .component {   display: flex;   flex-flow: column nowrap;   align-items: start;   padding: 32px;   gap: 32px; } .someElementContext .component .expandableContent {   display: none; } .someElementContext .component .collapsableContent {   display: contents; } .someElementContext .component[data-expanded=true] .expandableContent {   display: contents; } .someElementContext .component[data-expanded=true] .collapsableContent {   display: none; }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u0440\u0435\u0430\u043a\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435.<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u044d\u0439\u0442\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 data-\u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>data-expanded<\/code> &#8212; \u043e\u043d \u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0410 css \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 <code>[data-expanded=true]<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>display<\/code> \u0438\u0437 <code>none<\/code> \u0432 <code>contents<\/code> (<code>display: contents<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0442\u0430\u043a, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442) \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445-\u043e\u0431\u0451\u0440\u0442\u043a\u0430\u0445 <code>.expandableContent<\/code> &amp; <code>.collapsableContent<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 html \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435.<\/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\/post\/708822\/\"> https:\/\/habr.com\/ru\/post\/708822\/<\/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, \u0425\u0430\u0431\u0440! \u0420\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0432 \u043f\u043b\u0430\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f html data-attributes &amp; css selectors. <\/p>\n<p>Html data-attributes &#8212; \u044d\u0442\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043a\u0443\u0434\u0430-\u0443\u0433\u043e\u0434\u043d\u043e \u0438 \u0441 \u043a\u0430\u043a\u0438\u043c \u0443\u0433\u043e\u0434\u043d\u043e \u0438\u043c\u0435\u043d\u0435\u043c (\u043d\u043e \u0438\u043c\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 <code>data-<\/code>). \u0417\u0430\u0442\u0435\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 css \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u0445, \u0447\u0442\u043e\u0431\u044b \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0443\u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u0414\u0432\u0438\u0436\u043e\u043a \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 data-\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 css \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u041a\u043e\u0434 \u0440\u0435\u0430\u043a\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0433\u0434\u0435 \u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043a\u043d\u043e\u043f\u043a\u0438 \u0447\u0442\u043e-\u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"typescript\">import React, {useState} from \"react\";  const ComponentWithExpandableContent = () => {     const [expanded, setExpanded] = useState(false)      return &lt;div style={{         display: 'flex',         flexFlow: 'column nowrap',         alignItems: 'start',         padding: 32,         gap: 32,     }}>          { !expanded &amp;&amp; &lt;div>Initial content&lt;\/div> }          &lt;button onClick={()=>setExpanded(!expanded)}>             { !expanded ? 'Expand' : 'Collapse' }         &lt;\/button>          { expanded &amp;&amp; &lt;div>Additional content&lt;\/div> }         { expanded &amp;&amp; &lt;div>More additional content&lt;\/div> }      &lt;\/div> } export default React.memo(ComponentWithExpandableContent)<\/code><\/pre>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>expanded=false<\/code>:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <code>expanded=true<\/code>:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e <code>html css js<\/code>.<\/p>\n<p>\u0424\u0430\u0439\u043b <code>emulating-use-state.html:<\/code><\/p>\n<pre><code class=\"xml\">&lt;!DOCTYPE html> &lt;html lang=\"en\"> &lt;head>   &lt;meta charset=\"UTF-8\">   &lt;title>     \u042d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c React useState \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c JS      (via data-attributes &amp; css selectors)   &lt;\/title>   &lt;link rel=\"stylesheet\" type=\"text\/css\" href=\"emulating-use-state.css\"> &lt;\/head> &lt;body>  &lt;script>   function toggleExpand(){     const element = document.getElementById('component')     if (element.dataset.expanded!=='true'){       element.dataset.expanded = 'true'     } else {       element.dataset.expanded = 'false'     }   } &lt;\/script>  &lt;div class=\"someElementContext\">   &lt;!-- data-expanded \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 -->   &lt;div id=\"component\" class=\"component\" data-expanded=\"false\">          &lt;div class=\"collapsableContent\">       &lt;div>Initial content&lt;\/div>     &lt;\/div>          &lt;button onClick=\"toggleExpand()\">       &lt;div class=\"collapsableContent\">Expand&lt;\/div>       &lt;div class=\"expandableContent\">Collapse&lt;\/div>     &lt;\/button>        &lt;div class=\"expandableContent\">       &lt;div>Additional content&lt;\/div>     &lt;\/div>     &lt;div class=\"expandableContent\">       &lt;div>More additional content&lt;\/div>     &lt;\/div>        &lt;\/div> &lt;\/div>  &lt;\/body> &lt;\/html><\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b \u0441\u0442\u0438\u043b\u0435\u0439 <code>emulating-use-state.scss:<\/code><\/p>\n<pre><code class=\"css\">.someElementContext {   display: contents;      .component {     display: flex;     flex-flow: column nowrap;     align-items: start;     padding: 32px;     gap: 32px;          \/\/ \u041a\u043b\u0430\u0441\u0441\u044b, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435     \/\/ \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f data-expanded     .expandableContent {       display: none;     }     .collapsableContent {       display: contents;     }     &amp;[data-expanded=true] .expandableContent {       display: contents;     }     &amp;[data-expanded=true] .collapsableContent {       display: none;     }   } }<\/code><\/pre>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0440\u0435\u0434\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <code>emulating-use-state.css:<\/code> <\/p>\n<pre><code class=\"css\">.someElementContext {   display: contents; } .someElementContext .component {   display: flex;   flex-flow: column nowrap;   align-items: start;   padding: 32px;   gap: 32px; } .someElementContext .component .expandableContent {   display: none; } .someElementContext .component .collapsableContent {   display: contents; } .someElementContext .component[data-expanded=true] .expandableContent {   display: contents; } .someElementContext .component[data-expanded=true] .collapsableContent {   display: none; }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u0440\u0435\u0430\u043a\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435.<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u044d\u0439\u0442\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 data-\u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>data-expanded<\/code> &#8212; \u043e\u043d \u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0410 css \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 <code>[data-expanded=true]<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>display<\/code> \u0438\u0437 <code>none<\/code> \u0432 <code>contents<\/code> (<code>display: contents<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0442\u0430\u043a, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442) \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445-\u043e\u0431\u0451\u0440\u0442\u043a\u0430\u0445 <code>.expandableContent<\/code> &amp; <code>.collapsableContent<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 html \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435.<\/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\/post\/708822\/\"> https:\/\/habr.com\/ru\/post\/708822\/<\/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-343426","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343426","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=343426"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343426\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}