{"id":347683,"date":"2023-05-19T15:03:04","date_gmt":"2023-05-19T15:03:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347683"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347683","title":{"rendered":"<span>\u0414\u0435\u043b\u0430\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e \u0434\u043b\u044f React<\/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<h2>\u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432<\/h2>\n<p>\u0425\u043e\u0447\u0435\u0448\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043b\u043e\u0432, \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430 ? \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0435\u043c\u043a\u0443 <a href=\"https:\/\/codesandbox.io\/s\/robzarel-custom-modal-14b1b4\" rel=\"noopener noreferrer nofollow\">codesandbox.custom-modal<\/a>.<\/p>\n<p>\u0410 \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0431\u0440\u0438\u0433\u0430\u0434\u0430 \u043a \u0434\u0435\u043c\u043a\u0435 \u0436\u0434\u0451\u0442 \u0432\u0430\u0441 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443)<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h2>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h2>\n<ol>\n<li>\n<p><a href=\"#%D0%B4%D1%83%D0%BC%D0%B0%D0%B5%D0%BC-%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D1%83%D0%B5%D0%BC\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%82-%D0%BF%D0%BE%D1%80%D1%82%D0%B0%D0%BB\" rel=\"noopener noreferrer nofollow\">\u041f\u0438\u0448\u0435\u043c \u043f\u043e\u0440\u0442\u0430\u043b<\/a> + <a href=\"#%D0%BD%D0%B5-%D0%B7%D0%B0%D0%B1%D1%8B%D0%B2%D0%B0%D0%B5%D0%BC-%D0%BF%D1%80%D0%BE-%D1%82%D0%B5%D1%81%D1%82%D1%8B\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043f\u043e\u0440\u0442\u0430\u043b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%82-%D0%BC%D0%BE%D0%B4%D0%B0%D0%BB%D0%BA%D0%B8\" rel=\"noopener noreferrer nofollow\">\u041f\u0438\u0448\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u043a\u0443<\/a> + <a href=\"#%D1%82%D0%B5%D1%81%D1%82%D0%B8%D1%80%D1%83%D0%B5%D0%BC-%D0%BD%D0%BE%D0%B2%D0%BE%D1%80%D0%BE%D0%B6%D0%B4%D1%91%D0%BD%D0%BD%D0%BE%D0%B5-%D0%BC%D0%BE%D0%B4%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5-%D0%BE%D0%BA%D0%BD%D0%BE\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043c\u043e\u0434\u0430\u043b\u043a\u0443<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%B7%D0%B0%D0%BF%D1%83%D1%81%D0%BA%D0%B0%D0%B5%D0%BC-%D0%B2%D1%81%D1%91-%D0%B2-%D0%BA%D0%BE%D0%BD%D1%82%D0%B5%D0%B9%D0%BD%D0%B5%D1%80%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0444\u0438\u0442<\/p>\n<\/li>\n<\/ol>\n<h2>\u0414\u0443\u043c\u0430\u0435\u043c \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c<\/h2>\n<p>\u0414\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e. \u041d\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443, \u043d\u0435 \u0434\u0440\u043e\u043f\u0434\u0430\u0443\u043d, \u043d\u0435 pop-up \u0438\u043d\u0444\u043e \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0448\u043a\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0434\u0430\u043b\u043a\u0443. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u0443\u0442\u044c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430, \u044d\u0442\u043e (\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e) \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0444\u043b\u043e\u0443 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f\/\u043e\u0442\u043c\u0435\u043d\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>\u041f\u0440\u043e \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f popup\/modals\/lightboxes\/tooltip\/notice \u0434\u0435\u0442\u0430\u043b\u0438 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0433\u0443\u0433\u043b\u044f\u0442\u0441\u044f. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0433\u043b\u044f\u043d\u0443\u0442\u044c <a href=\"https:\/\/balsamiq.com\/learn\/ui-control-guidelines\/popups-modals-lightboxes\/#:~:text=them%20very%20sparingly.-,Modals,%2C%20adding%20content%2C%20and%20more.\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0443<\/a> \u0438 <a href=\"https:\/\/ux.stackexchange.com\/a\/90337\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0443<\/a> \u0441\u0441\u044b\u043b\u043a\u0438.<\/p>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\/\u043e\u0442\u043b\u0438\u0447\u0438\u044f, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 &#8212; \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <strong>\u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435<\/strong>.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0442\u0443\u0442 \u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e React, \u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0444\u0438\u0448\u043a\u0438, \u043f\u043e\u0440\u0442\u0430\u043b\u044b.<\/p>\n<p>\u0418 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u0440\u0442\u0430\u043b\u044b, \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u044e\u0431\u044b\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0430\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f 2 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u043f\u043e\u0440\u0442\u0430\u043b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0432\u043d\u043e\u0432\u044b<\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0434\u0430\u043b\u043a\u0443, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430\u0434 \u043f\u043e\u0440\u0442\u0430\u043b\u043e\u043c<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0440\u0442\u0430\u043b\u043e\u0432 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e, \u0430 \u043c\u043e\u0434\u0430\u043b\u043a\u0430 \u043e\u0434\u043d\u0430.<\/p>\n<p>\u041c\u043e\u0434\u0430\u043b\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u043e\u0440\u0442\u0430\u043b\u0430, \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u044f \u0432 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 (\u043c\u043e\u0434\u0430\u043b\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438), \u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 (\u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f).<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u044b, \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430.<\/p>\n<h2>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e\u0440\u0442\u0430\u043b<\/h2>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 &#8212; \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 (children) \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c id.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438, \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"https:\/\/react.dev\/reference\/react-dom\/createPortal\" rel=\"noopener noreferrer nofollow\">createPortal<\/a>.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0432 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u043e\u0440\u0442\u0430\u043b.<\/p>\n<p>\u042f\u0432\u043d\u043e\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u044f\u0432\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u043c\u044b \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0443\u0440\u043e\u043d\u0438\u043c \u043d\u0430\u0448\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430.<\/p>\n<pre><code class=\"typescript\">import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom';  type PortalProps = { id: string; children: React.ReactNode; };  const PORTAL_ERROR_MSG ='There is no portal container in markup. Please add portal container with proper id attribute.';  const Portal = (props: PortalProps) =&gt; {   const { id, children } = props;   const [container, setContainer] = useState&lt;HTMLElement&gt;();    useEffect(() =&gt; {     if (id) {       const portalContainer = document.getElementById(id);        if (!portalContainer) {         throw new Error(PORTAL_ERROR_MSG);       }        setContainer(portalContainer);     }   }, [id]);    return container ? createPortal(children, container) : null; }; <\/code><\/pre>\n<p>\u041c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u043e\u0434\u0430, \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0441\u0442\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0430\u043f\u0433\u0440\u0435\u0439\u0434\u0438\u043c.<\/p>\n<h3>\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0443\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u0435\u0435<\/h3>\n<p>\u041f\u043e\u0440\u0442\u0430\u043b \u044d\u0442\u043e\u0442 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043a\u0435\u0439\u0441\u043e\u0432. \u0412 \u043c\u043e\u0434\u0430\u043b\u043a\u0435, \u0432 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0448\u043a\u0430\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445, \u0432 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430\u0445 \u0438\u043b\u0438 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u043f\u0438\u0441\u043a\u0430\u0445.<\/p>\n<p>\u0418 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0440\u0443\u043a\u0430\u043c\u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043d\u0435 \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430.<\/p>\n<p>\u0415\u0451 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c div \u0441 \u043d\u0443\u0436\u043d\u044b\u043c <strong>id<\/strong>, \u0438 \u0437\u0430\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 <strong>moundNode<\/strong>. \u041d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c (\u0437\u0430\u0447\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0434\u0451\u0440\u0433\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 dom \u0434\u0435\u0440\u0435\u0432\u043e). \u041d\u0443 \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <strong>moundNode<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f <strong>document.body<\/strong>:<\/p>\n<pre><code class=\"typescript\">type containerOptions = { id: string; mountNode?: HTMLElement };  const createContainer = (options : containerOptions) =&gt; {   if (document.getElementById(options.id)) {     return;   }    const { id, mountNode = document.body } = options;      const portalContainer = document.createElement('div');    portalContainer.setAttribute('id', id);   mountNode.appendChild(portalContainer); }; <\/code><\/pre>\n<p>\u0418 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451 \u043d\u0430\u0448\u0435 \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"typescript\">export { createContainer, PORTAL_ERROR_MSG }; export default Portal; <\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448 \u043f\u043e\u0440\u0442\u0430\u043b \u0433\u043e\u0442\u043e\u0432. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0440\u0442\u0430\u043b\u043e\u043c \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0430 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<h3>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e \u0442\u0435\u0441\u0442\u044b<\/h3>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0443 \u043d\u0430\u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 2 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e 2 \u0448\u0442\u0443\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0430\u0432\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430 (mountNode || document.body)<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 (rendreing || throw new Error).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0432 \u0444\u0430\u0439\u043b \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">import '@testing-library\/jest-dom'; import { render, screen } from '@testing-library\/react';  import Portal, { createContainer, PORTAL_ERROR_MSG } from '.\/index';  describe('Portal:', () =&gt; {   const mountNodeId = 'mount-node-id';   const containerId = 'container-id';   ... }); ... <\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c <strong>data-testid<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0430 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0435\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u0435.<\/p>\n<pre><code class=\"typescript\">const createContainer = (options : containerOptions) =&gt; {   ...   const { id, ...} = options;    portalContainer.setAttribute('data-testid', `portalContainer-${id}`);   ... }; <\/code><\/pre>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/h4>\n<pre><code class=\"typescript\">  describe('CreateContainer:', () =&gt; {     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0432 document.body', async () =&gt; {       createContainer({ id: containerId });        const container = screen.getByTestId(`portalContainer-${containerId}`);        expect(container).toBeInTheDocument();     });     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u043e\u0434\u0435', async () =&gt; {       render(         &lt;div id={mountNodeId} data-testid={mountNodeId}&gt;&lt;\/div&gt;       );        const mountNode = screen.getByTestId(mountNodeId);       createContainer({ id: containerId, mountNode });        const container = screen.getByTestId(`portalContainer-${containerId}`);        expect(mountNode).toContainElement(container);     });   }); <\/code><\/pre>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/h4>\n<pre><code class=\"typescript\">describe('React Portal', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043d\u043e\u0434\u0435', async () =&gt; {     const containerId = 'container-id';          render(       &lt;&gt;         &lt;div id={containerId} data-testid='some-test-id'&gt;&lt;\/div&gt;         &lt;Portal id={containerId}&gt;           some text         &lt;\/Portal&gt;       &lt;\/&gt;     );      const container = screen.getByTestId('some-test-id');     expect(container).toContainHTML('some text');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430', async () =&gt; {     const containerId = 'container-id';      expect(() =&gt; render(       &lt;Portal id={containerId}&gt;         some text       &lt;\/Portal&gt;     ))     .toThrow(PORTAL_ERROR_MSG);   });  });  <\/code><\/pre>\n<h4>\u041d\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441<\/h4>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0443 \u043d\u0430\u0441 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u0441\u044f 2 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/p>\n<ol>\n<li>\n<p>jest \u043d\u0435 \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0434\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u042d\u0442\u043e \u043d\u0430\u0434\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u043d\u0441\u043e\u043b\u044c jest \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u0435\u0442\u0438\u0442\u0441\u044f \u043a\u0440\u043e\u0432\u0430\u0432\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441\u043e\u043c, \u0445\u043e\u0442\u044f \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u0442\u0435\u0441\u0442 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f beforeEach \u0438 afterEach) \u043c\u044b \u0437\u0430\u043c\u043e\u043a\u0430\u0435\u043c console.error \u0438 \u0440\u0443\u0447\u043a\u0430\u043c\u0438 \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u043c body \u0432 \u043d\u0430\u0448\u0435\u043c dom \u0434\u0435\u0440\u0435\u0432\u0435.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443:<\/p>\n<pre><code class=\"typescript\">beforeEach(() =&gt; {   jest.spyOn(console, 'error')   \/\/ @ts-ignore    console.error.mockImplementation(() =&gt; null); });  afterEach(() =&gt; {   \/\/ @ts-ignore   console.error.mockRestore(); }) <\/code><\/pre>\n<p>\u0410 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0432 \u0440\u0443\u0447\u043d\u0443\u044e <strong>\u043e\u0447\u0438\u0449\u0430\u0442\u044c document.body<\/strong> \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">afterEach(() =&gt; {   \/\/ eslint-disable-next-line testing-library\/no-node-access   document.getElementsByTagName('body')[0].innerHTML = '';  }) <\/code><\/pre>\n<p>PS:<br \/> \u0418\u0433\u043d\u043e\u0440 ts-ignore \u043f\u0438\u0448\u0435\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>&#171;Property &#8216;mockImplementation&#8217; does not exist on type &#171;<\/p>\n<\/li>\n<li>\n<p>Property &#8216;mockRestore&#8217; does not exist on type<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/jestjs.io\/docs\/jest-object#jestspyonobject-methodname\" rel=\"noopener noreferrer nofollow\">jest.spyOn<\/a> \u043d\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<h2>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0434\u0430\u043b\u043a\u0438<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0431\u0435\u0440\u0451\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432\u0441\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u044e\u0430\u043d\u0441\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043e\u0448\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0438\u043a\u0442\u0443\u044e\u0442 \u043d\u0430\u043c \u043b\u043e\u0433\u0438\u043a\u0430, \u0437\u0434\u0440\u0430\u0432\u044b\u0439 \u0441\u043c\u044b\u0441\u043b \u0438 \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 UX:<\/p>\n<ul>\n<li>\n<p>\u043c\u043e\u0434\u0430\u043b\u043a\u0443 \u0434\u0435\u043b\u0430\u0435\u043c <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0451 \u0432 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0432\u043b\u0430\u0434\u0435\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0435\u0437\u0440\u0430\u0434\u0435\u043b\u044c\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/strong>: <\/p>\n<ul>\n<li>\n<p>\u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043f\u043e\u0434\u043b\u043e\u0436\u043a\u0443, \u0442.\u0435. \u043d\u0430 overlay (\u043f\u043e \u043a\u043b\u0438\u043a\u0443 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430)<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 escape<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0418 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f +- \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h3>\u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043f\u043e\u0440\u0442\u0430\u043b \u0438 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e <strong>createContainer<\/strong> \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 <strong>id<\/strong>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430, \u0447\u0442\u043e\u0431\u044b \u0434\u0451\u0440\u0433\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u043e\u0440\u0442\u0430\u043b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430:<\/p>\n<pre><code class=\"typescript\">import { useEffect, useState } from 'react'; import Portal, { createContainer } from '..\/portal';  const MODAL_CONTAINER_ID = 'modal-container-id';  const Modal = () =&gt; {   const [isMounted, setMounted] = useState(false);    useEffect(() =&gt; {     createContainer({ id: MODAL_CONTAINER_ID });     setMounted(true);   }, []);    return (     isMounted     ? (&lt;Portal id={MODAL_CONTAINER_ID}&gt;...&lt;\/Portal&gt;)     : null   ); };  export default Modal; <\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430<\/h3>\n<h4>\u041f\u043e \u043a\u043d\u043e\u043f\u043a\u0435 &#171;\u0437\u0430\u043a\u0440\u044b\u0442\u044c&#187;<\/h4>\n<pre><code class=\"typescript\">import { ..., useCallback, useRef } from 'react'; import type { MouseEventHandler } from 'react'; ...  import Styles from '.\/index.module.css';  type Props = { onClose?: () =&gt; void; };  const Modal = (props: Props) =&gt; {   const { onClose } = props;    const rootRef = useRef&lt;HTMLDivElement&gt;(null);   ...   const handleClose: MouseEventHandler&lt;HTMLButtonElement&gt; =     useCallback(() =&gt; {       onClose?.();     }, [onClose]);    return (     isMounted     ? (       &lt;Portal id={MODAL_CONTAINER_ID}&gt;         &lt;div className={Styles.wrap} ref={rootRef}&gt;           &lt;div className={Styles.content}&gt;             &lt;button               type=\"button\"               className={Styles.closeButton}               onClick={handleClose}               &gt;               x             &lt;\/button&gt;             ...           &lt;\/div&gt;         &lt;\/div&gt;       &lt;\/Portal&gt;     )     : null   ); }; <\/code><\/pre>\n<h4>\u041f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 &#171;escape&#187; \u0438 \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 &#171;overlay&#187;<\/h4>\n<pre><code class=\"typescript\">const Modal = (props: Props) =&gt; {   ...   useEffect(() =&gt; {     const handleWrapperClick = (event: MouseEvent) =&gt; {       const { target } = event;        if (target instanceof Node &amp;&amp; rootRef.current === target) {         onClose?.();       }     };     const handleEscapePress = (event: KeyboardEvent) =&gt; {       if (event.key === 'Escape') {         onClose?.();       }     };      window.addEventListener('click', handleWrapperClick);     window.addEventListener('keydown', handleEscapePress);      return () =&gt; {       window.removeEventListener('click', handleWrapperClick);       window.removeEventListener('keydown', handleEscapePress);     };   }, [onClose]);    return (...); }; <\/code><\/pre>\n<h3>\u0420\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c Props<\/h3>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0440 \u0434\u043b\u044f \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u0438. \u041c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0451\u0440\u0441\u0442\u043a\u0443 \u043a\u0430\u043a \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0442\u0438\u043b\u0438\u0442\u0430\u0440\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <strong>title<\/strong> \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0430\u043b\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0435\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435. \u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 <strong>children<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c.<\/p>\n<pre><code class=\"typescript\">type Props = { ..., title: string; children: React.ReactNode;};  const Modal = (props: Props) =&gt; {   const { ..., title, children } = props;   ...   return (     isMounted     ? (       &lt;Portal id={MODAL_CONTAINER_ID}&gt;         &lt;div className={Styles.wrap} ref={rootRef}&gt;           &lt;div className={Styles.content}&gt;             ...             &lt;p className={Styles.title}&gt;{title}&lt;\/p&gt;             {children}           &lt;\/div&gt;         &lt;\/div&gt;       &lt;\/Portal&gt;     )     : null   ); }; <\/code><\/pre>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u043e\u0435 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c 2 \u0433\u0440\u0443\u043f\u043f\u044b \u0434\u043b\u044f \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433)<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 onClose<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0432 \u0444\u0430\u0439\u043b \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">import '@testing-library\/jest-dom'; import { render, fireEvent, screen } from '@testing-library\/react';  import Modal from '.\/index';  describe('Modal:', () =&gt; {...}); ... <\/code><\/pre>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c, \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0438 <strong>data-testid<\/strong>. \u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0438 \u043a\u043d\u043e\u043f\u043a\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">&lt;div className={Styles.wrap} {\/* rest props *\/} data-testid=\"wrap\"&gt; ... &lt;button className={Styles.closeButton} {\/* rest props *\/} data-testid=\"modal-close-button\"&gt;x&lt;\/button&gt; ... <\/code><\/pre>\n<h4>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/h4>\n<pre><code class=\"typescript\">  describe('\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435:', () =&gt; {     it('\u0414\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f title', async () =&gt; {       render(         &lt;Modal title=\"title\" onClose={jest.fn()}&gt;           children         &lt;\/Modal&gt;       );          const title = screen.queryByText('title');       expect(title).toBeInTheDocument();     });     it('\u0414\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f children (\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442)', async () =&gt; {       render(         &lt;Modal title=\"title\" onClose={jest.fn()}&gt;           some text         &lt;\/Modal&gt;       );          const children = screen.queryByText('some text');       expect(children).toBeInTheDocument();     });   }); <\/code><\/pre>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/h4>\n<pre><code class=\"typescript\">  describe('\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f:', () =&gt; {     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \"onClose\" \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \"\u0437\u0430\u043a\u0440\u044b\u0442\u044c\"', async () =&gt; {       const handleClose = jest.fn();          render(         &lt;Modal title=\"title\" onClose={handleClose}&gt;           children         &lt;\/Modal&gt;       );          const wrapper = screen.getByTestId('modal-close-button');       fireEvent.click(wrapper);          expect(handleClose).toHaveBeenCalledTimes(1);     });     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \"onClose\" \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 wrapper (\u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430)', async () =&gt; {       const handleClose = jest.fn();          render(         &lt;Modal title=\"title\" onClose={handleClose}&gt;           children         &lt;\/Modal&gt;       );          const wrapper = screen.getByTestId('wrap');       fireEvent.click(wrapper);          expect(handleClose).toHaveBeenCalledTimes(1);     });     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \"onClose\" \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \"escape\"', async () =&gt; {       const handleClose = jest.fn();          render(         &lt;Modal title=\"title\" onClose={handleClose}&gt;           children         &lt;\/Modal&gt;       );          const wrapper = screen.getByTestId('wrap');       fireEvent.keyDown(wrapper, { key: 'Escape', code: 'Escape' });          expect(handleClose).toHaveBeenCalledTimes(1);     });   }); <\/code><\/pre>\n<h3>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/h3>\n<p>\u0420\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u043c\u043e\u0434\u0430\u043b\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e <strong>useState<\/strong>:<\/p>\n<pre><code class=\"typescript\">import { useState } from \"react\";  import Modal from \".\/components\/modal\";  import \".\/styles.css\";  export default function App() {   const [isModalActive, setModalActive] = useState(false);    const handleModalOpen = () =&gt; {     setModalActive(true);   };   const handleModalClose = () =&gt; {     setModalActive(false);   };    return (     &lt;div className=\"App\"&gt;       &lt;h1&gt;Custom Modal component Demo&lt;\/h1&gt;       &lt;button className=\"button\" type=\"button\" onClick={handleModalOpen}&gt;         open modal       &lt;\/button&gt;       &lt;div&gt;         {isModalActive &amp;&amp; (           &lt;Modal title=\"some modal title\" onClose={handleModalClose}&gt;             Hello world           &lt;\/Modal&gt;         )}       &lt;\/div&gt;     &lt;\/div&gt;   ); } <\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433\u043e<\/h2>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e\u0440\u0442\u0430\u043b\u0430<\/strong>, \u043f\u043e\u0432\u0435\u0440\u0445 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0448\u0435\u043a \u0438 \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0436\u0438\u0437\u043d\u0438<\/p>\n<\/li>\n<li>\n<p><strong>\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0412 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043e\u043d \u0443\u043c\u0435\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p><strong>\u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c<\/strong> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u043e\u043c\u0430\u0435\u043c <strong>\u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e<\/strong> \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u043a\u0435\/\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435, \u0432\u0435\u0434\u044c \u043c\u044b \u0432\u0441\u0451 \u043f\u043e\u043a\u0440\u044b\u043b\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u0447\u0438 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0430\u0448\u0438\u0445 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432)<\/p>\n<p>PS<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li>\n<p>\u0414\u0435\u043c\u043e <a href=\"https:\/\/codesandbox.io\/s\/robzarel-custom-modal-14b1b4\" rel=\"noopener noreferrer nofollow\">codesandbox.custom-modal<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0435\u0435 <\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/react.dev\/reference\/react-dom\/createPortal\" rel=\"noopener noreferrer nofollow\">createPortal<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/jestjs.io\/docs\/jest-object#jestspyonobject-methodname\" rel=\"noopener noreferrer nofollow\">jest.spyOn<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e \u0432\u0438\u0434\u044b \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0448\u0435\u043a: <a href=\"https:\/\/balsamiq.com\/learn\/ui-control-guidelines\/popups-modals-lightboxes\/#:~:text=them%20very%20sparingly.-,Modals,%2C%20adding%20content%2C%20and%20more.\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437<\/a> \u0438 <a href=\"https:\/\/ux.stackexchange.com\/a\/90337\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0430<\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0438\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/735724\/\" rel=\"noopener noreferrer nofollow\">RadioGroup<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/735224\/\" rel=\"noopener noreferrer nofollow\">Select<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/734980\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e<\/a><\/p>\n<\/li>\n<\/ul>\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\/articles\/736284\/\"> https:\/\/habr.com\/ru\/articles\/736284\/<\/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<h2>\u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432<\/h2>\n<p>\u0425\u043e\u0447\u0435\u0448\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043b\u043e\u0432, \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430 ? \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0435\u043c\u043a\u0443 <a href=\"https:\/\/codesandbox.io\/s\/robzarel-custom-modal-14b1b4\" rel=\"noopener noreferrer nofollow\">codesandbox.custom-modal<\/a>.<\/p>\n<p>\u0410 \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0431\u0440\u0438\u0433\u0430\u0434\u0430 \u043a \u0434\u0435\u043c\u043a\u0435 \u0436\u0434\u0451\u0442 \u0432\u0430\u0441 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443)<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h2>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h2>\n<ol>\n<li>\n<p><a href=\"#%D0%B4%D1%83%D0%BC%D0%B0%D0%B5%D0%BC-%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D1%83%D0%B5%D0%BC\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%82-%D0%BF%D0%BE%D1%80%D1%82%D0%B0%D0%BB\" rel=\"noopener noreferrer nofollow\">\u041f\u0438\u0448\u0435\u043c \u043f\u043e\u0440\u0442\u0430\u043b<\/a> + <a href=\"#%D0%BD%D0%B5-%D0%B7%D0%B0%D0%B1%D1%8B%D0%B2%D0%B0%D0%B5%D0%BC-%D0%BF%D1%80%D0%BE-%D1%82%D0%B5%D1%81%D1%82%D1%8B\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043f\u043e\u0440\u0442\u0430\u043b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%82-%D0%BC%D0%BE%D0%B4%D0%B0%D0%BB%D0%BA%D0%B8\" rel=\"noopener noreferrer nofollow\">\u041f\u0438\u0448\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u043a\u0443<\/a> + <a href=\"#%D1%82%D0%B5%D1%81%D1%82%D0%B8%D1%80%D1%83%D0%B5%D0%BC-%D0%BD%D0%BE%D0%B2%D0%BE%D1%80%D0%BE%D0%B6%D0%B4%D1%91%D0%BD%D0%BD%D0%BE%D0%B5-%D0%BC%D0%BE%D0%B4%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5-%D0%BE%D0%BA%D0%BD%D0%BE\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043c\u043e\u0434\u0430\u043b\u043a\u0443<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%B7%D0%B0%D0%BF%D1%83%D1%81%D0%BA%D0%B0%D0%B5%D0%BC-%D0%B2%D1%81%D1%91-%D0%B2-%D0%BA%D0%BE%D0%BD%D1%82%D0%B5%D0%B9%D0%BD%D0%B5%D1%80%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0444\u0438\u0442<\/p>\n<\/li>\n<\/ol>\n<h2>\u0414\u0443\u043c\u0430\u0435\u043c \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c<\/h2>\n<p>\u0414\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e. \u041d\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443, \u043d\u0435 \u0434\u0440\u043e\u043f\u0434\u0430\u0443\u043d, \u043d\u0435 pop-up \u0438\u043d\u0444\u043e \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0448\u043a\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0434\u0430\u043b\u043a\u0443. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u0443\u0442\u044c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430, \u044d\u0442\u043e (\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e) \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0444\u043b\u043e\u0443 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f\/\u043e\u0442\u043c\u0435\u043d\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>\u041f\u0440\u043e \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f popup\/modals\/lightboxes\/tooltip\/notice \u0434\u0435\u0442\u0430\u043b\u0438 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0433\u0443\u0433\u043b\u044f\u0442\u0441\u044f. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0433\u043b\u044f\u043d\u0443\u0442\u044c <a href=\"https:\/\/balsamiq.com\/learn\/ui-control-guidelines\/popups-modals-lightboxes\/#:~:text=them%20very%20sparingly.-,Modals,%2C%20adding%20content%2C%20and%20more.\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0443<\/a> \u0438 <a href=\"https:\/\/ux.stackexchange.com\/a\/90337\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0443<\/a> \u0441\u0441\u044b\u043b\u043a\u0438.<\/p>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\/\u043e\u0442\u043b\u0438\u0447\u0438\u044f, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 &#8212; \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <strong>\u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435<\/strong>.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0442\u0443\u0442 \u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e React, \u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0444\u0438\u0448\u043a\u0438, \u043f\u043e\u0440\u0442\u0430\u043b\u044b.<\/p>\n<p>\u0418 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u0440\u0442\u0430\u043b\u044b, \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u044e\u0431\u044b\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0430\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f 2 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u043f\u043e\u0440\u0442\u0430\u043b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0432\u043d\u043e\u0432\u044b<\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0434\u0430\u043b\u043a\u0443, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430\u0434 \u043f\u043e\u0440\u0442\u0430\u043b\u043e\u043c<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0440\u0442\u0430\u043b\u043e\u0432 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e, \u0430 \u043c\u043e\u0434\u0430\u043b\u043a\u0430 \u043e\u0434\u043d\u0430.<\/p>\n<p>\u041c\u043e\u0434\u0430\u043b\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u043e\u0440\u0442\u0430\u043b\u0430, \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u044f \u0432 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 (\u043c\u043e\u0434\u0430\u043b\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438), \u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 (\u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f).<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u044b, \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430.<\/p>\n<h2>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e\u0440\u0442\u0430\u043b<\/h2>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 &#8212; \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 (children) \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c id.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438, \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"https:\/\/react.dev\/reference\/react-dom\/createPortal\" rel=\"noopener noreferrer nofollow\">createPortal<\/a>.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0432 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u043e\u0440\u0442\u0430\u043b.<\/p>\n<p>\u042f\u0432\u043d\u043e\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u044f\u0432\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u043c\u044b \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0443\u0440\u043e\u043d\u0438\u043c \u043d\u0430\u0448\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430.<\/p>\n<pre><code class=\"typescript\">import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom';  type PortalProps = { id: string; children: React.ReactNode; };  const PORTAL_ERROR_MSG ='There is no portal container in markup. Please add portal container with proper id attribute.';  const Portal = (props: PortalProps) =&gt; {   const { id, children } = props;   const [container, setContainer] = useState&lt;HTMLElement&gt;();    useEffect(() =&gt; {     if (id) {       const portalContainer = document.getElementById(id);        if (!portalContainer) {         throw new Error(PORTAL_ERROR_MSG);       }        setContainer(portalContainer);     }   }, [id]);    return container ? createPortal(children, container) : null; }; <\/code><\/pre>\n<p>\u041c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u043e\u0434\u0430, \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0441\u0442\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0430\u043f\u0433\u0440\u0435\u0439\u0434\u0438\u043c.<\/p>\n<h3>\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0443\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u0435\u0435<\/h3>\n<p>\u041f\u043e\u0440\u0442\u0430\u043b \u044d\u0442\u043e\u0442 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043a\u0435\u0439\u0441\u043e\u0432. \u0412 \u043c\u043e\u0434\u0430\u043b\u043a\u0435, \u0432 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0448\u043a\u0430\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445, \u0432 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430\u0445 \u0438\u043b\u0438 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u043f\u0438\u0441\u043a\u0430\u0445.<\/p>\n<p>\u0418 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0440\u0443\u043a\u0430\u043c\u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043d\u0435 \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430.<\/p>\n<p>\u0415\u0451 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c div \u0441 \u043d\u0443\u0436\u043d\u044b\u043c <strong>id<\/strong>, \u0438 \u0437\u0430\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 <strong>moundNode<\/strong>. \u041d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c (\u0437\u0430\u0447\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0434\u0451\u0440\u0433\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 dom \u0434\u0435\u0440\u0435\u0432\u043e). \u041d\u0443 \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <strong>moundNode<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f <strong>document.body<\/strong>:<\/p>\n<pre><code class=\"typescript\">type containerOptions = { id: string; mountNode?: HTMLElement };  const createContainer = (options : containerOptions) =&gt; {   if (document.getElementById(options.id)) {     return;   }    const { id, mountNode = document.body } = options;      const portalContainer = document.createElement('div');    portalContainer.setAttribute('id', id);   mountNode.appendChild(portalContainer); }; <\/code><\/pre>\n<p>\u0418 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451 \u043d\u0430\u0448\u0435 \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"typescript\">export { createContainer, PORTAL_ERROR_MSG }; export default Portal; <\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448 \u043f\u043e\u0440\u0442\u0430\u043b \u0433\u043e\u0442\u043e\u0432. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0440\u0442\u0430\u043b\u043e\u043c \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0430 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<h3>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e \u0442\u0435\u0441\u0442\u044b<\/h3>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0443 \u043d\u0430\u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 2 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e 2 \u0448\u0442\u0443\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0430\u0432\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430 (mountNode || document.body)<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 (rendreing || throw new Error).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0432 \u0444\u0430\u0439\u043b \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">import '@testing-library\/jest-dom'; import { render, screen } from '@testing-library\/react';  import Portal, { createContainer, PORTAL_ERROR_MSG } from '.\/index';  describe('Portal:', () =&gt; {   const mountNodeId = 'mount-node-id';   const containerId = 'container-id';   ... }); ... <\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c <strong>data-testid<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0430 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0435\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u0435.<\/p>\n<pre><code class=\"typescript\">const createContainer = (options : containerOptions) =&gt; {   ...   const { id, ...} = options;    portalContainer.setAttribute('data-testid', `portalContainer-${id}`);   ... }; <\/code><\/pre>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/h4>\n<pre><code class=\"typescript\">  describe('CreateContainer:', () =&gt; {     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0432 document.body', async () =&gt; {       createContainer({ id: containerId });        const container = screen.getByTestId(`portalContainer-${containerId}`);        expect(container).toBeInTheDocument();     });     it('\u0414\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0430\u043b\u0430 \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u043e\u0434\u0435', async () =&gt; {       render(         &lt;div id={mountNodeId} data-testid={mountNodeId}&gt;&lt;\/div&gt;       );        const mountNode = screen.getByTestId(mountNodeId);       createContainer({ id: containerId, mountNode });        const container = screen.getByTestId(`portalContainer-${containerId}`);        expect(mountNode).toContainElement(container);     });   }); <\/code><\/pre>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/h4>\n<pre><code class=\"typescript\">describe('React Portal', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043d\u043e\u0434\u0435', async () =&gt; {     const containerId = 'container-id';          render(       &lt;&gt;         &lt;div id={containerId} data-testid='some-test-id'&gt;&lt;\/div&gt;         &lt;Portal id={containerId}&gt;           some text         &lt;\/Portal&gt;       &lt;\/&gt;     );      const container = screen.getByTestId('some-test-id');     expect(container).toContainHTML('some text');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043f\u043e\u0440\u0442\u0430\u043b\u0430', async () =&gt; {     const containerId = 'container-id';      expect(() =&gt; render(       &lt;Portal id={containerId}&gt;         some text       &lt;\/Portal&gt;     ))     .toThrow(PORTAL_ERROR_MSG);   });  });  <\/code><\/pre>\n<h4>\u041d\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441<\/h4>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0443 \u043d\u0430\u0441 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u0441\u044f 2 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/p>\n<ol>\n<li>\n<p>jest \u043d\u0435 \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0434\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u042d\u0442\u043e \u043d\u0430\u0434\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u043d\u0441\u043e\u043b\u044c jest \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u0435\u0442\u0438\u0442\u0441\u044f \u043a\u0440\u043e\u0432\u0430\u0432\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0441\u0442\u0435\u043a\u0442\u0440\u0435\u0439\u0441\u043e\u043c, \u0445\u043e\u0442\u044f \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u0442\u0435\u0441\u0442 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f beforeEach \u0438 afterEach) \u043c\u044b \u0437\u0430\u043c\u043e\u043a\u0430\u0435\u043c console.error \u0438 \u0440\u0443\u0447\u043a\u0430\u043c\u0438 \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u043c body \u0432 \u043d\u0430\u0448\u0435\u043c dom \u0434\u0435\u0440\u0435\u0432\u0435.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443:<\/p>\n<pre><code class=\"typescript\">beforeEach(() =&gt; {   jest.spyOn(console, 'error')   \/\/ @ts-ignore    console.error.mockImplementation(() =&gt; null); });  afterEach(() =&gt; {   \/\/ @ts-ignore   console.error.mockRestore(); }) <\/code><\/pre>\n<p>\u0410 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0432 \u0440\u0443\u0447\u043d\u0443\u044e <strong>\u043e\u0447\u0438\u0449\u0430\u0442\u044c document.body<\/strong> \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">afterEach(() =&gt; {   \/\/ eslint-disable-next-line testing-library\/no-node-access   document.getElementsByTagName('body')[0].innerHTML = '';  }) <\/code><\/pre>\n<p>PS:<br \/> \u0418\u0433\u043d\u043e\u0440 ts-ignore \u043f\u0438\u0448\u0435\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>&#171;Property &#8216;mockImplementation&#8217; does not exist on type &#171;<\/p>\n<\/li>\n<li>\n<p>Property &#8216;mockRestore&#8217; does not exist on type<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/jestjs.io\/docs\/jest-object#jestspyonobject-methodname\" rel=\"noopener noreferrer nofollow\">jest.spyOn<\/a> \u043d\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<h2>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0434\u0430\u043b\u043a\u0438<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0431\u0435\u0440\u0451\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432\u0441\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u044e\u0430\u043d\u0441\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043e\u0448\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0438\u043a\u0442\u0443\u044e\u0442 \u043d\u0430\u043c \u043b\u043e\u0433\u0438\u043a\u0430, \u0437\u0434\u0440\u0430\u0432\u044b\u0439 \u0441\u043c\u044b\u0441\u043b \u0438 \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 UX:<\/p>\n<ul>\n<li>\n<p>\u043c\u043e\u0434\u0430\u043b\u043a\u0443 \u0434\u0435\u043b\u0430\u0435\u043c <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0451 \u0432 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0432\u043b\u0430\u0434\u0435\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0435\u0437\u0440\u0430\u0434\u0435\u043b\u044c\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/strong>: <\/p>\n<ul>\n<li>\n<p>\u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043f\u043e\u0434\u043b\u043e\u0436\u043a\u0443, \u0442.\u0435. \u043d\u0430 overlay (\u043f\u043e \u043a\u043b\u0438\u043a\u0443 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430)<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 escape<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0418 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f +- \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h3>\u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043f\u043e\u0440\u0442\u0430\u043b \u0438 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e <strong>createContainer<\/strong> \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 <strong>id<\/strong>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430, \u0447\u0442\u043e\u0431\u044b \u0434\u0451\u0440\u0433\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u043e\u0440\u0442\u0430\u043b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430:<\/p>\n<pre><code class=\"typescript\">import { useEffect, useState } from 'react'; import Portal, { createContainer } from '..\/portal';  const MODAL_CONTAINER_ID = 'modal-container-id';  const Modal = () =&gt; {   const [isMounted, setMounted] = useState(false);    useEffect(() =&gt; {     createContainer({ id: MODAL_CONTAINER_ID });     setMounted(true);   }, []);    return (     isMounted     ? (&lt;Portal id={MODAL_CONTAINER_ID}&gt;...&lt;\/Portal&gt;)     : null   ); };  export default Modal; <\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430<\/h3>\n<h4>\u041f\u043e \u043a\u043d\u043e\u043f\u043a\u0435 &#171;\u0437\u0430\u043a\u0440\u044b\u0442\u044c&#187;<\/h4>\n<pre><code class=\"typescript\">import { ..., useCallback, useRef } from 'react'; import type { MouseEventHandler } from 'react'; ...  import Styles from '.\/index.module.css';  type Props = { onClose?: () =&gt; void; };  const Modal = (props: Props) =&gt; {   const { onClose } = props;    const rootRef = useRef&lt;HTMLDivElement&gt;(null);   ...   const handleClose: MouseEventHandler&lt;HTMLButtonElement&gt; =     useCallback(() =&gt; {       onClose?.();     }, [onClose]);    return (     isMounted     ? (       &lt;Portal id={MODAL_CONTAINER_ID}&gt;         &lt;div className={Styles.wrap} ref={rootRef}&gt;           &lt;div className={Styles.content}&gt;             &lt;button               type=\"button\"               className={Styles.closeButton}               onClick={handleClose}               &gt;               x             &lt;\/button&gt;             ...           &lt;\/div&gt;         &lt;\/div&gt;       &lt;\/Portal&gt;     )     : null   ); }; <\/code><\/pre>\n<h4>\u041f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 &#171;escape&#187; \u0438 \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 &#171;overlay&#187;<\/h4>\n<pre><code class=\"typescript\">const Modal = (props: Props) =&gt; {   ...   useEffect(() =&gt; {     const handleWrapperClick = (event: MouseEvent) =&gt; {       const { target } = event;        if (target<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\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-347683","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347683","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=347683"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347683\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}