{"id":309710,"date":"2020-09-09T21:00:22","date_gmt":"2020-09-09T21:00:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309710"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-09-09T21:00:22","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309710","title":{"rendered":"React: \u0441\u043b\u043e\u0442\u044b \u043a\u0430\u043a \u0443 \u0441\u044b\u043d\u0430 \u043c\u0430\u043c\u0438\u043d\u043e\u0439 \u043f\u043e\u0434\u0440\u0443\u0433\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518500\/\">\n<p>\u041f\u0440\u0438 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0442\u043e\u0447\u0435\u0447\u043d\u043e\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>DatePicker<\/strong>, \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c&#187;.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f &#171;\u0441\u043b\u043e\u0442\u043e\u0432&#187;. \u0423 Angular \u044d\u0442\u043e <a href=\"https:\/\/habr.com\/ru\/post\/491136\/\" rel=\"noopener noreferrer nofollow\">ngContent<\/a>, \u0432\u043e <a href=\"https:\/\/ru.vuejs.org\/v2\/guide\/components-slots.html\" rel=\"noopener noreferrer nofollow\">Vue<\/a>, <a href=\"https:\/\/ru.svelte.dev\/docs#slot\" rel=\"noopener noreferrer nofollow\">Svelte<\/a> \u0438 <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/HTML\/Element\/slot\" rel=\"noopener noreferrer nofollow\">WebComponents<\/a> \u044d\u0442\u043e \u0441\u043b\u043e\u0442\u044b. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 React \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0441\u043b\u043e\u0442\u043e\u0432 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0435\u0442. <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 React \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043b\u0438\u0431\u043e \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0441\u0432\u043e\u0438\u0445 \u0434\u0435\u0442\u0435\u0439 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u043b\u0438\u0431\u043e &#171;\u0437\u0430\u043b\u0435\u0437\u0442\u044c&#187; \u0432 \u043d\u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/ru.reactjs.org\/docs\/react-api.html#reactchildren\" rel=\"noopener noreferrer nofollow\">React.Children<\/a> API \u0438 \u0442\u043e\u0447\u0435\u0447\u043d\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 <a href=\"https:\/\/ru.reactjs.org\/docs\/render-props.html\" rel=\"noopener noreferrer nofollow\">renderProps<\/a>, \u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445:<\/p>\n<pre><code class=\"htmlmixed\">&lt;MyComponent renderFooter={data =&gt; (&lt;h1&gt;Bye, ${data.name}&lt;\/h1&gt;)}\/&gt;<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434 \u0441 renderProps, \u0432 \u0446\u0435\u043b\u043e\u043c, \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u044a\u044f\u043d\u043e\u0432. \u0420\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e, \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0442\u0430\u043c\u0438. \u0412 NPM \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <a href=\"https:\/\/www.npmjs.com\/package\/react-view-slot\" rel=\"noopener noreferrer nofollow\">react-view-slot<\/a>, \u043d\u043e \u043c\u043d\u0435 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u043f\u0440\u043e\u0441\u0442\u043e, \u0440\u0435\u0448\u0430\u044e\u0442 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 <a href=\"http:\/\/lurkmore.to\/%D0%A4%D0%B0%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9_%D0%BD%D0%B5%D0%B4%D0%BE%D1%81%D1%82%D0%B0%D1%82%D0%BE%D0%BA\" rel=\"noopener noreferrer nofollow\">\u0444\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a<\/a>, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a.<\/p>\n<h4>\u0412\u0438\u0436\u0443 \u0446\u0435\u043b\u044c \u2013&nbsp;\u043d\u0435 \u0432\u0438\u0436\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0435 API \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c. \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043c\u043e\u0439 \u043d\u0430\u0431\u0440\u043e\u0441\u043e\u043a \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<pre><code class=\"javascript\">const Component = props =&gt; {   Component.NameSlot = useSlot(props.children);    return (     &lt;div&gt;       &lt;h1&gt;         &lt;Component.NameSlot.Receiver&gt;           Default value         &lt;\/Component.NameSlot.Receiver&gt;       &lt;\/h1&gt;        Hello {props.children}     &lt;\/div&gt;   ); };  function App() {   return (     &lt;div&gt;       Hello!       &lt;Component&gt;         Foo         &lt;Component.NameSlot&gt;           Bobobo         &lt;\/Component.NameSlot&gt;       &lt;\/Component&gt;     &lt;\/div&gt;   ); }<\/code><\/pre>\n<p>\u0418\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u043b\u043e\u0442\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0435\u0439 \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435.<\/p>\n<p>\u041d\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u044d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e. \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u2013&nbsp;\u044d\u0442\u043e, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d, \u0438 \u0442\u0443\u0434\u0430 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u043a \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0443\u0436\u0435 API, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0435 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435:<\/p>\n<pre><code class=\"javascript\">import {createSlot} from 'react-slotify';  export const MySlot = createSlot();  export const Component = ({children}) =&gt; {   return (     &lt;div&gt;       This component contains slot:              &lt;MySlot.Renderer childs={children}&gt;         This is default slot content       &lt;\/MySlot.Renderer&gt;              &lt;div&gt;It also renders children: {children}&lt;\/div&gt;     &lt;\/div&gt;   ); };<\/code><\/pre>\n<pre><code class=\"javascript\">import {Component, MySlot} from '.\/component';  const App = () =&gt; {   return (     &lt;div&gt;       &lt;Component&gt;         &lt;MySlot&gt;Slotted content&lt;\/MySlot&gt;         Other content       &lt;\/Component&gt;     &lt;\/div&gt;   ); };<\/code><\/pre>\n<h4>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h4>\n<p>\u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 API, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u2013&nbsp;\u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <strong>MySlot<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442 \u0441\u0432\u043e\u0438\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <strong>{children}<\/strong>, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d <strong>MySlot.Renderer<\/strong>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c JS-\u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e:<\/p>\n<pre><code class=\"javascript\">export function createSlot() {   const Slot = ({ children, showChildren }) =&gt; {     return showChildren ? children : null;   }    const Renderer = ({ childs, children }) =&gt; {     const slotted = React.Children.toArray(childs).find(child =&gt; {       return React.isValidElement(child) &amp;&amp; child.type === Slot;     });      if (!slotted || !React.isValidElement(slotted)) {       return children;     }     return React.cloneElement(slotted, { showChildren: true });   };    Slot.Renderer = Renderer;    return Slot; }<\/code><\/pre>\n<p>\u0414\u0430-\u0434\u0430, \u0432\u0441\u0435\u0433\u043e 20 \u0441\u0442\u0440\u043e\u0447\u0435\u043a. \u041d\u043e \u0438\u0434\u0435\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 \u044d\u0442\u043e\u043c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c React-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u043d\u0435 \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2013&nbsp;\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Slot<\/strong>. \u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"javascript\">export function createSlot() {   const Slot = ({ children, showChildren }) =&gt; {     return showChildren ? children : null;   }   return Slot; }<\/code><\/pre>\n<p>\u0412\u0441\u0451, \u0447\u0442\u043e \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Slot<\/strong> \u2013&nbsp;\u044d\u0442\u043e \u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0441\u0432\u043e\u0438\u0445 \u0434\u0435\u0442\u0435\u0439 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0432 \u043d\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u043f\u0440\u043e\u043f <strong>showChildren={true}<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0442 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u044b \u044d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <strong>Slot<\/strong> \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u044f\u0447\u0435\u0442 \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.<\/p>\n<p>\u0422\u0443\u0442 \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2013&nbsp;<strong>Renderer<\/strong>. \u0415\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u2013&nbsp;\u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u0430\u0439\u0442\u0438 \u0441\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c <strong>Slot<\/strong>-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e, \u0441\u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0432 \u0435\u0433\u043e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0435\u043c\u0443 <strong>showChildren={true}<\/strong>:<\/p>\n<pre><code class=\"javascript\">  const Renderer = ({ childs, children }) =&gt; {     const slotted = React.Children.toArray(childs).find(child =&gt; {       return React.isValidElement(child) &amp;&amp; child.type === Slot;     });      if (!slotted || !React.isValidElement(slotted)) {       return children;     }     return React.cloneElement(slotted, { showChildren: true });   };<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <strong>Renderer<\/strong> \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u0441\u0432\u043e\u0438\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432, \u0438 \u0440\u0438\u0441\u0443\u0435\u0442 \u0438\u0445 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 <strong>Slot<\/strong> \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d. \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0441\u043b\u043e\u0442\u0430.<\/p>\n<p>\u041d\u0443 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2013&nbsp;\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Renderer<\/strong> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <strong>Slot<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <strong>&lt;MySlot.Renderer\/&gt;<\/strong>.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 20 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a\u043e\u0434\u0430 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u0445, \u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432 React. <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>react-slotify<\/strong> \u043d\u0430 <a href=\"https:\/\/github.com\/andrey-skl\/react-slotify\" rel=\"noopener noreferrer nofollow\">GitHub<\/a> \u0438 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 \u0432 <a href=\"https:\/\/www.npmjs.com\/package\/react-slotify\" rel=\"noopener noreferrer nofollow\">NPM<\/a>. \u0423\u0436\u0435 \u043d\u0430 TypeScript \u0438 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/andrey-skl\/react-slotify#passing-props-back-from-inside-slot\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0442\u043e\u0432<\/a>. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u0440\u0438\u0442\u0438\u043a\u0435. <\/p>\n<\/p>\n<\/div>\n<p> \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\/518500\/\"> https:\/\/habr.com\/ru\/post\/518500\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518500\/\">\n<p>\u041f\u0440\u0438 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0442\u043e\u0447\u0435\u0447\u043d\u043e\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>DatePicker<\/strong>, \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c&#187;.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f &#171;\u0441\u043b\u043e\u0442\u043e\u0432&#187;. \u0423 Angular \u044d\u0442\u043e <a href=\"https:\/\/habr.com\/ru\/post\/491136\/\" rel=\"noopener noreferrer nofollow\">ngContent<\/a>, \u0432\u043e <a href=\"https:\/\/ru.vuejs.org\/v2\/guide\/components-slots.html\" rel=\"noopener noreferrer nofollow\">Vue<\/a>, <a href=\"https:\/\/ru.svelte.dev\/docs#slot\" rel=\"noopener noreferrer nofollow\">Svelte<\/a> \u0438 <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/HTML\/Element\/slot\" rel=\"noopener noreferrer nofollow\">WebComponents<\/a> \u044d\u0442\u043e \u0441\u043b\u043e\u0442\u044b. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 React \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0441\u043b\u043e\u0442\u043e\u0432 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0435\u0442. <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 React \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043b\u0438\u0431\u043e \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0441\u0432\u043e\u0438\u0445 \u0434\u0435\u0442\u0435\u0439 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u043b\u0438\u0431\u043e &#171;\u0437\u0430\u043b\u0435\u0437\u0442\u044c&#187; \u0432 \u043d\u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/ru.reactjs.org\/docs\/react-api.html#reactchildren\" rel=\"noopener noreferrer nofollow\">React.Children<\/a> API \u0438 \u0442\u043e\u0447\u0435\u0447\u043d\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 <a href=\"https:\/\/ru.reactjs.org\/docs\/render-props.html\" rel=\"noopener noreferrer nofollow\">renderProps<\/a>, \u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445:<\/p>\n<pre><code class=\"htmlmixed\">&lt;MyComponent renderFooter={data =&gt; (&lt;h1&gt;Bye, ${data.name}&lt;\/h1&gt;)}\/&gt;<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434 \u0441 renderProps, \u0432 \u0446\u0435\u043b\u043e\u043c, \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u044a\u044f\u043d\u043e\u0432. \u0420\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e, \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0442\u0430\u043c\u0438. \u0412 NPM \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <a href=\"https:\/\/www.npmjs.com\/package\/react-view-slot\" rel=\"noopener noreferrer nofollow\">react-view-slot<\/a>, \u043d\u043e \u043c\u043d\u0435 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u043f\u0440\u043e\u0441\u0442\u043e, \u0440\u0435\u0448\u0430\u044e\u0442 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 <a href=\"http:\/\/lurkmore.to\/%D0%A4%D0%B0%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9_%D0%BD%D0%B5%D0%B4%D0%BE%D1%81%D1%82%D0%B0%D1%82%D0%BE%D0%BA\" rel=\"noopener noreferrer nofollow\">\u0444\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a<\/a>, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a.<\/p>\n<h4>\u0412\u0438\u0436\u0443 \u0446\u0435\u043b\u044c \u2013&nbsp;\u043d\u0435 \u0432\u0438\u0436\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0435 API \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c. \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043c\u043e\u0439 \u043d\u0430\u0431\u0440\u043e\u0441\u043e\u043a \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<pre><code class=\"javascript\">const Component = props =&gt; {   Component.NameSlot = useSlot(props.children);    return (     &lt;div&gt;       &lt;h1&gt;         &lt;Component.NameSlot.Receiver&gt;           Default value         &lt;\/Component.NameSlot.Receiver&gt;       &lt;\/h1&gt;        Hello {props.children}     &lt;\/div&gt;   ); };  function App() {   return (     &lt;div&gt;       Hello!       &lt;Component&gt;         Foo         &lt;Component.NameSlot&gt;           Bobobo         &lt;\/Component.NameSlot&gt;       &lt;\/Component&gt;     &lt;\/div&gt;   ); }<\/code><\/pre>\n<p>\u0418\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u043b\u043e\u0442\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0435\u0439 \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435.<\/p>\n<p>\u041d\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u044d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e. \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u2013&nbsp;\u044d\u0442\u043e, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d, \u0438 \u0442\u0443\u0434\u0430 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u043a \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0443\u0436\u0435 API, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0435 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435:<\/p>\n<pre><code class=\"javascript\">import {createSlot} from 'react-slotify';  export const MySlot = createSlot();  export const Component = ({children}) =&gt; {   return (     &lt;div&gt;       This component contains slot:              &lt;MySlot.Renderer childs={children}&gt;         This is default slot content       &lt;\/MySlot.Renderer&gt;              &lt;div&gt;It also renders children: {children}&lt;\/div&gt;     &lt;\/div&gt;   ); };<\/code><\/pre>\n<pre><code class=\"javascript\">import {Component, MySlot} from '.\/component';  const App = () =&gt; {   return (     &lt;div&gt;       &lt;Component&gt;         &lt;MySlot&gt;Slotted content&lt;\/MySlot&gt;         Other content       &lt;\/Component&gt;     &lt;\/div&gt;   ); };<\/code><\/pre>\n<h4>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h4>\n<p>\u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 API, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u2013&nbsp;\u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <strong>MySlot<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442 \u0441\u0432\u043e\u0438\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <strong>{children}<\/strong>, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d <strong>MySlot.Renderer<\/strong>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c JS-\u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e:<\/p>\n<pre><code class=\"javascript\">export function createSlot() {   const Slot = ({ children, showChildren }) =&gt; {     return showChildren ? children : null;   }    const Renderer = ({ childs, children }) =&gt; {     const slotted = React.Children.toArray(childs).find(child =&gt; {       return React.isValidElement(child) &amp;&amp; child.type === Slot;     });      if (!slotted || !React.isValidElement(slotted)) {       return children;     }     return React.cloneElement(slotted, { showChildren: true });   };    Slot.Renderer = Renderer;    return Slot; }<\/code><\/pre>\n<p>\u0414\u0430-\u0434\u0430, \u0432\u0441\u0435\u0433\u043e 20 \u0441\u0442\u0440\u043e\u0447\u0435\u043a. \u041d\u043e \u0438\u0434\u0435\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 \u044d\u0442\u043e\u043c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c React-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u043d\u0435 \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2013&nbsp;\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Slot<\/strong>. \u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"javascript\">export function createSlot() {   const Slot = ({ children, showChildren }) =&gt; {     return showChildren ? children : null;   }   return Slot; }<\/code><\/pre>\n<p>\u0412\u0441\u0451, \u0447\u0442\u043e \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Slot<\/strong> \u2013&nbsp;\u044d\u0442\u043e \u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0441\u0432\u043e\u0438\u0445 \u0434\u0435\u0442\u0435\u0439 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0432 \u043d\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u043f\u0440\u043e\u043f <strong>showChildren={true}<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0442 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u044b \u044d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <strong>Slot<\/strong> \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u044f\u0447\u0435\u0442 \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.<\/p>\n<p>\u0422\u0443\u0442 \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2013&nbsp;<strong>Renderer<\/strong>. \u0415\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u2013&nbsp;\u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u0430\u0439\u0442\u0438 \u0441\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c <strong>Slot<\/strong>-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e, \u0441\u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0432 \u0435\u0433\u043e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0435\u043c\u0443 <strong>showChildren={true}<\/strong>:<\/p>\n<pre><code class=\"javascript\">  const Renderer = ({ childs, children }) =&gt; {     const slotted = React.Children.toArray(childs).find(child =&gt; {       return React.isValidElement(child) &amp;&amp; child.type === Slot;     });      if (!slotted || !React.isValidElement(slotted)) {       return children;     }     return React.cloneElement(slotted, { showChildren: true });   };<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <strong>Renderer<\/strong> \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u0441\u0432\u043e\u0438\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432, \u0438 \u0440\u0438\u0441\u0443\u0435\u0442 \u0438\u0445 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 <strong>Slot<\/strong> \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d. \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0441\u043b\u043e\u0442\u0430.<\/p>\n<p>\u041d\u0443 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2013&nbsp;\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Renderer<\/strong> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <strong>Slot<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <strong>&lt;MySlot.Renderer\/&gt;<\/strong>.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 20 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a\u043e\u0434\u0430 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u0445, \u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432 React. <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>react-slotify<\/strong> \u043d\u0430 <a href=\"https:\/\/github.com\/andrey-skl\/react-slotify\" rel=\"noopener noreferrer nofollow\">GitHub<\/a> \u0438 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 \u0432 <a href=\"https:\/\/www.npmjs.com\/package\/react-slotify\" rel=\"noopener noreferrer nofollow\">NPM<\/a>. \u0423\u0436\u0435 \u043d\u0430 TypeScript \u0438 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/andrey-skl\/react-slotify#passing-props-back-from-inside-slot\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0442\u043e\u0432<\/a>. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u0440\u0438\u0442\u0438\u043a\u0435. <\/p>\n<\/p>\n<\/div>\n<p> \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\/518500\/\"> https:\/\/habr.com\/ru\/post\/518500\/<\/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-309710","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309710","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=309710"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309710\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}