组件是不确定的,是一个变量传入的,可以使用如下方法渲染
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