react動態渲染組件


組件是不確定的,是一個變量傳入的,可以使用如下方法渲染

export function insertModal(cfg){
    let {id,refKey,modal} = cfg;
    let ModalKey = modal || 'Modal';
    id = id || +new Date();
    let div = document.createElement('div');
    div.id = id;
    document.body.appendChild(div);
    refKey = refKey || 'myRef' + id;
    window[refKey + 'Ref'] = React.createRef();
    ReactDOM.render(React.createElement(ModalKey,{ref:window[refKey + 'Ref']}), div);
}

 

出處:https://stackoverflow.com/questions/29875869/react-jsx-dynamic-component-name


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM