How to dynamically add nodes in react

藏色散人
Release: 2022-12-29 11:48:01
Original
1946 people have browsed it

How to dynamically add nodes in react: 1. Display the pop-up box through the "KmcDialog.showInstance = function(properties) {...}" method; 2. Use "KmcDialog.showInstance({isShow: true}) ;KmcDialog.removeInstance();" method can be called directly where needed.

How to dynamically add nodes in react

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

How to dynamically add nodes in react?

React-Dynamic Insertion of Node Components

After introducing the component, you can insert the display component by calling it

/**********组件KmcDialog************/
/**
 * 显示弹框
 */
KmcDialog.showInstance = function(properties) {
    if (!document.getElementById("KmcDialog")) {
        let props = properties || {};
        let div = document.createElement('div');
        div.setAttribute('id', 'KmcDialog');
        document.body.appendChild(div);
        ReactDOM.render(React.createElement(KmcDialog, props), div);
    }
}
/**
 * 删除弹框
 */
KmcDialog.removeInstance = function() {
    if(document.getElementById("KmcDialog")) {
        document.getElementById('KmcDialog').remove();
    }
}
Copy after login

When you need to use Local direct call:

KmcDialog.showInstance({
    isShow: true
});
KmcDialog.removeInstance();
Copy after login

Recommended learning: "react video tutorial"

The above is the detailed content of How to dynamically add nodes in react. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!