如果我想用ReactJS节点替换DOM节点,怎么办?
const myComp = <span>hey</span>
const elem = document.getElementById('video1')
elem.parentNode.replaceChild(myComp, elem)
该怎么做?这不起作用
var temp = document.createElement('div')
ReactDOM.render(myComp, temp)
console.log(temp) // a node with the nested div element
console.log(temp.firstChild) // null (??)
console.log(temp.firstElementChild) // null (??)
elem.parentNode.replaceChild(temp.firstElementChild, elem) // error
答案 0 :(得分:0)
const elem = document.getElementById('video1')
...
ReactDOM.render(myComp, elem)