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