{"id":335793,"date":"2022-07-17T03:00:09","date_gmt":"2022-07-17T03:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=335793"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=335793","title":{"rendered":"<span>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a \u0431\u0430\u043b\u0443\u043d\u0443 \u043d\u0430\u0434 \u043c\u0435\u0442\u043a\u043e\u0439\/Placemark \u0432 react-yandex-maps, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f React.createPortal<\/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\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0432\u043d\u0443\u0442\u0440\u044c \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043a\u043d\u0430 \u043d\u0430\u0434 \u043c\u0435\u0442\u043a\u043e\u0439 \u043d\u0430 \u042f\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u0440\u0442\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/react-yandex-maps\" rel=\"noopener noreferrer nofollow\">react-yandex-maps<\/a> + <a href=\"https:\/\/react-yandex-maps.vercel.app\/?path=\/story\/getting-started--page\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0438 \u043a \u043d\u0435\u043c\u0443<\/a><\/p>\n<p>\u0422\u0430\u043c \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0448\u044c \u042f\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u0440\u0442\u044b \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437.<\/p>\n<p>\u0422\u043e, \u0447\u0435\u0433\u043e \u044f \u0434\u043e\u0431\u0438\u0432\u0430\u043b\u0441\u044f, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/364\/d14\/af4\/364d14af46fe7c8c1176abf4c360e2ff.jpg\" width=\"574\" height=\"466\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/364\/d14\/af4\/364d14af46fe7c8c1176abf4c360e2ff.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0432 react-yandex-map \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0445\u043e\u0442\u044f \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u044d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0435\u0437\u043e\u043d\u043d\u043e. \u0415\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0443\u0436\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (\u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 ReactDomServer.<a href=\"https:\/\/www.tabnine.com\/code\/javascript\/functions\/react-dom\/renderToString\" rel=\"noopener noreferrer nofollow\"><strong>renderToString<\/strong><\/a>), \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<p>\u041d\u0430\u043c \u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u0441\u0442\u0435\u0439\u0442\u0443 \u0438 \u0432\u0441\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0443 React. \u041d\u0430 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 &#171;\u0445\u043e\u0442\u0435\u043b\u043a\u0438&#187; \u043c\u0435\u043d\u044f \u043d\u0430\u0432\u0451\u043b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 EgorKluch \u0432 <a href=\"https:\/\/github.com\/gribnoysup\/react-yandex-maps\/issues\/27\" rel=\"noopener noreferrer nofollow\">issues <\/a>\u043a react-yandex-map \u043d\u0430 github, \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <strong>ReacDom.Portal<\/strong>, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u043e\u043d \u0442\u0430\u043a \u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b. \u0417\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u043e\u0432\u043e. Portal \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d, \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0443\u0442\u044c \u043b\u0438 \u043d\u0435 \u043d\u0430 \u0442\u044d\u0433 &lt;body>. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e, \u0442\u0443\u0434\u0430 \u044f \u0438 \u0441\u0442\u0430\u043b \u043a\u043e\u043f\u0430\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \/ \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d c\u0430\u043c\u043e\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 Portal, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/p>\n<pre><code class=\"javascript\">import React, {useEffect} from 'react'; import {createPortal} from 'react-dom';   export const Portal =     ( { children, getHTMLElementId } ) => {         \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 HTML \u043f\u043e id         const mount = document.getElementById(elementId)         \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0432\u043e\u0439 div         const el = document.createElement('div')          useEffect(() => {             \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439 \u0434\u0438\u0432 \u043a \u0438\u0441\u043a\u043e\u043c\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443             if (mount) mount.appendChild(el)             return () => {                 \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b                 if (mount) mount.removeChild(el)             }         }, [ el, mount ])                 \/\/ \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0443 \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         if (!mount) return null         \/\/ \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u0438\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u043c React-\u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 div \u043a \u0438\u0441\u043a\u043e\u043c\u043e\u043c\u0443 HTML         return createPortal(children, el)     }<\/code><\/pre>\n<p>\u041f\u043e\u0442\u043e\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">import React from 'react' import '.\/yandex-map-restyle-ballon.scss' \/\/ \u0441\u0442\u0438\u043b\u0438 \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u044b \u0438 \u0431\u0430\u043b\u0443\u043d\u0430 import {Map, Placemark} from 'react-yandex-maps'   export const MapSection = () => {    const [ activePortal, setActivePortal ] = useState(false)    return (     &lt;section className={'map-section'}> &lt;Map          state={ {          center:{[55.773733, 37.608771]}, \/\/ \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u0430\u0440\u0442\u044b          zoom: 10, \/\/ \u0437\u0443\u043c \u043e\u043d \u0438 \u0435\u0441\u0442\u044c \u0437\u0443\u043c          \/\/ \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0438, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u043a\u043d\u0430 \u043d\u0430\u0434 \u0433\u0435\u043e\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438          modules={ [ 'geoObject.addon.balloon', 'geoObject.addon.hint' ] }         >             \/\/ \u0420\u0438\u0441\u0443\u0435\u043c \u043c\u0435\u0442\u043a\u0443             &lt;Placemark geometry={ [55.847973, 37.692542] }               options={                 {                   preset: 'islands#circleIcon', \/\/ \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0435\u043c\u043f\u043b\u0435\u0439\u0442\u043e\u0432 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u044f\u043d\u0434\u0435\u043a\u0441\u0430                   iconColor: 'green', \/\/ \u0446\u0432\u0435\u0442 \u0438\u043a\u043e\u043d\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432 hex                 } }               properties={                 {                 iconContent: '2', \/\/ \u043f\u0430\u0440\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f                 hintContent: '&lt;b> \u042f \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0441\u044c \u043f\u0440\u0438 \u043d\u0430\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043d\u0430 \u043c\u0435\u0442\u043a\u0443 &lt;\/b>',                 \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438                 balloonContent: '&lt;div id=\"driver-2\" class=\"driver-card\">&lt;\/div>',               }}               onClick={ () => {               \/\/ \u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0431\u0430\u043b\u0443\u043d\u0430               setTimeout(() => { setActivePortal(true)}, 0)               } } \/>       &lt;\/Map> {\/* \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0440\u0442\u0430\u043b *\/} {     activePortal &amp;&amp; &lt;Portal getHTMLElementId={ 'driver-2' }> \/\/ \u0421\u0442\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442                       &lt;BallonComponent\/> &lt;\/Portal>   }   &lt;\/section> )<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u043b\u0443\u043d \u043f\u0440\u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435<\/p>\n<pre><code class=\"css\">.driver-card {   width: 240px;   height: 400px;   \/\/ \u0438\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 400px \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0441 \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u043e\u0439 }  .ymaps-2-1-79-balloon {   box-shadow: none !important; }  .ymaps-2-1-79-balloon__content {   padding: 0 !important;   background: transparent !important;   margin: 0 !important; }  .ymaps-2-1-79-balloon__layout {   background: transparent !important;   border: none !important; }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e \u044f\u043d\u0434\u0435\u043a\u0441-\u043a\u0430\u0440\u0442 \u043f\u0440\u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"typescript\">&lt;YMaps version={ '2.1.79' }> &lt;App>&lt;\/App> &lt;\/YMaps><\/code><\/pre>\n<p>\u0412\u043e\u0442, \u0432\u0440\u043e\u0434\u0435 \u0431\u044b, \u0438 \u0432\u0441\u0451. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435, \u044f \u0443\u0442\u043e\u0447\u043d\u044e \u0438\u043d\u0444\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/677330\/\"> https:\/\/habr.com\/ru\/post\/677330\/<\/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\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0432\u043d\u0443\u0442\u0440\u044c \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043a\u043d\u0430 \u043d\u0430\u0434 \u043c\u0435\u0442\u043a\u043e\u0439 \u043d\u0430 \u042f\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u0440\u0442\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/react-yandex-maps\" rel=\"noopener noreferrer nofollow\">react-yandex-maps<\/a> + <a href=\"https:\/\/react-yandex-maps.vercel.app\/?path=\/story\/getting-started--page\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0438 \u043a \u043d\u0435\u043c\u0443<\/a><\/p>\n<p>\u0422\u0430\u043c \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0448\u044c \u042f\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u0440\u0442\u044b \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437.<\/p>\n<p>\u0422\u043e, \u0447\u0435\u0433\u043e \u044f \u0434\u043e\u0431\u0438\u0432\u0430\u043b\u0441\u044f, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0432 react-yandex-map \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0445\u043e\u0442\u044f \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u044d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0435\u0437\u043e\u043d\u043d\u043e. \u0415\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0443\u0436\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (\u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 ReactDomServer.<a href=\"https:\/\/www.tabnine.com\/code\/javascript\/functions\/react-dom\/renderToString\" rel=\"noopener noreferrer nofollow\"><strong>renderToString<\/strong><\/a>), \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<p>\u041d\u0430\u043c \u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u0441\u0442\u0435\u0439\u0442\u0443 \u0438 \u0432\u0441\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0443 React. \u041d\u0430 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 &#171;\u0445\u043e\u0442\u0435\u043b\u043a\u0438&#187; \u043c\u0435\u043d\u044f \u043d\u0430\u0432\u0451\u043b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 EgorKluch \u0432 <a href=\"https:\/\/github.com\/gribnoysup\/react-yandex-maps\/issues\/27\" rel=\"noopener noreferrer nofollow\">issues <\/a>\u043a react-yandex-map \u043d\u0430 github, \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <strong>ReacDom.Portal<\/strong>, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u043e\u043d \u0442\u0430\u043a \u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b. \u0417\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u043e\u0432\u043e. Portal \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d, \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0443\u0442\u044c \u043b\u0438 \u043d\u0435 \u043d\u0430 \u0442\u044d\u0433 &lt;body>. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e, \u0442\u0443\u0434\u0430 \u044f \u0438 \u0441\u0442\u0430\u043b \u043a\u043e\u043f\u0430\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \/ \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d c\u0430\u043c\u043e\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 Portal, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/p>\n<pre><code class=\"javascript\">import React, {useEffect} from 'react'; import {createPortal} from 'react-dom';   export const Portal =     ( { children, getHTMLElementId } ) => {         \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 HTML \u043f\u043e id         const mount = document.getElementById(elementId)         \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0432\u043e\u0439 div         const el = document.createElement('div')          useEffect(() => {             \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439 \u0434\u0438\u0432 \u043a \u0438\u0441\u043a\u043e\u043c\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443             if (mount) mount.appendChild(el)             return () => {                 \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b                 if (mount) mount.removeChild(el)             }         }, [ el, mount ])                 \/\/ \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0443 \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         if (!mount) return null         \/\/ \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u0438\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u043c React-\u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 div \u043a \u0438\u0441\u043a\u043e\u043c\u043e\u043c\u0443 HTML         return createPortal(children, el)     }<\/code><\/pre>\n<p>\u041f\u043e\u0442\u043e\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">import React from 'react' import '.\/yandex-map-restyle-ballon.scss' \/\/ \u0441\u0442\u0438\u043b\u0438 \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u044b \u0438 \u0431\u0430\u043b\u0443\u043d\u0430 import {Map, Placemark} from 'react-yandex-maps'   export const MapSection = () => {    const [ activePortal, setActivePortal ] = useState(false)    return (     &lt;section className={'map-section'}> &lt;Map          state={ {          center:{[55.773733, 37.608771]}, \/\/ \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u0430\u0440\u0442\u044b          zoom: 10, \/\/ \u0437\u0443\u043c \u043e\u043d \u0438 \u0435\u0441\u0442\u044c \u0437\u0443\u043c          \/\/ \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0438, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u043a\u043d\u0430 \u043d\u0430\u0434 \u0433\u0435\u043e\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438          modules={ [ 'geoObject.addon.balloon', 'geoObject.addon.hint' ] }         >             \/\/ \u0420\u0438\u0441\u0443\u0435\u043c \u043c\u0435\u0442\u043a\u0443             &lt;Placemark geometry={ [55.847973, 37.692542] }               options={                 {                   preset: 'islands#circleIcon', \/\/ \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0435\u043c\u043f\u043b\u0435\u0439\u0442\u043e\u0432 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u044f\u043d\u0434\u0435\u043a\u0441\u0430                   iconColor: 'green', \/\/ \u0446\u0432\u0435\u0442 \u0438\u043a\u043e\u043d\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432 hex                 } }               properties={                 {                 iconContent: '2', \/\/ \u043f\u0430\u0440\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f                 hintContent: '&lt;b> \u042f \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0441\u044c \u043f\u0440\u0438 \u043d\u0430\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043d\u0430 \u043c\u0435\u0442\u043a\u0443 &lt;\/b>',                 \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438                 balloonContent: '&lt;div id=\"driver-2\" class=\"driver-card\">&lt;\/div>',               }}               onClick={ () => {               \/\/ \u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0431\u0430\u043b\u0443\u043d\u0430               setTimeout(() => { setActivePortal(true)}, 0)               } } \/>       &lt;\/Map> {\/* \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0440\u0442\u0430\u043b *\/} {     activePortal &amp;&amp; &lt;Portal getHTMLElementId={ 'driver-2' }> \/\/ \u0421\u0442\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442                       &lt;BallonComponent\/> &lt;\/Portal>   }   &lt;\/section> )<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u043b\u0443\u043d \u043f\u0440\u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435<\/p>\n<pre><code class=\"css\">.driver-card {   width: 240px;   height: 400px;   \/\/ \u0438\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 400px \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0441 \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u043e\u0439 }  .ymaps-2-1-79-balloon {   box-shadow: none !important; }  .ymaps-2-1-79-balloon__content {   padding: 0 !important;   background: transparent !important;   margin: 0 !important; }  .ymaps-2-1-79-balloon__layout {   background: transparent !important;   border: none !important; }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e \u044f\u043d\u0434\u0435\u043a\u0441-\u043a\u0430\u0440\u0442 \u043f\u0440\u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"typescript\">&lt;YMaps version={ '2.1.79' }> &lt;App>&lt;\/App> &lt;\/YMaps><\/code><\/pre>\n<p>\u0412\u043e\u0442, \u0432\u0440\u043e\u0434\u0435 \u0431\u044b, \u0438 \u0432\u0441\u0451. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435, \u044f \u0443\u0442\u043e\u0447\u043d\u044e \u0438\u043d\u0444\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/677330\/\"> https:\/\/habr.com\/ru\/post\/677330\/<\/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-335793","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335793","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=335793"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335793\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}