SWEBDEV Telegram 3199
Использование createPortal для рендеринга компонентов вне DOM-иерархии в React

Метод createPortal в React позволяет рендерить компоненты вне текущей DOM-структуры. Это полезно для создания модальных окон, всплывающих меню или уведомлений, которые должны отображаться поверх остальных элементов без влияния родительских стилей и позиционирования.

Создание уведомления, рендерящегося в отдельном узле DOM:
import React from 'react';
import ReactDOM from 'react-dom';

function Notification({ message }) {
return ReactDOM.createPortal(
<div className="notification">
{message}
</div>,
document.getElementById('notification-root')
);
}

В этом примере компонент Notification рендерится в элемент с ID notification-root, который находится вне основного DOM-дерева приложения. Это позволяет отображать уведомление поверх других компонентов без конфликтов стилей и вложенности.

👉 @sWebDev
👍4



tgoop.com/sWebDev/3199
Create:
Last Update:

Использование createPortal для рендеринга компонентов вне DOM-иерархии в React

Метод createPortal в React позволяет рендерить компоненты вне текущей DOM-структуры. Это полезно для создания модальных окон, всплывающих меню или уведомлений, которые должны отображаться поверх остальных элементов без влияния родительских стилей и позиционирования.

Создание уведомления, рендерящегося в отдельном узле DOM:

import React from 'react';
import ReactDOM from 'react-dom';

function Notification({ message }) {
return ReactDOM.createPortal(
<div className="notification">
{message}
</div>,
document.getElementById('notification-root')
);
}

В этом примере компонент Notification рендерится в элемент с ID notification-root, который находится вне основного DOM-дерева приложения. Это позволяет отображать уведомление поверх других компонентов без конфликтов стилей и вложенности.

👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tgoop.com/sWebDev/3199

View MORE
Open in Telegram


Telegram News

Date: |

The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information. How to create a business channel on Telegram? (Tutorial) There have been several contributions to the group with members posting voice notes of screaming, yelling, groaning, and wailing in different rhythms and pitches. Calling out the “degenerate” community or the crypto obsessives that engage in high-risk trading, Co-founder of NFT renting protocol Rentable World emiliano.eth shared this group on his Twitter. He wrote: “hey degen, are you stressed? Just let it out all out. Voice only tg channel for screaming”. Telegram offers a powerful toolset that allows businesses to create and manage channels, groups, and bots to broadcast messages, engage in conversations, and offer reliable customer support via bots. To view your bio, click the Menu icon and select “View channel info.”
from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM American