我需要通过深层嵌套组件进行事件冒泡,我试着做一些像下面这样的事情
import {ReactDOM,render, unmountComponentAtNode} from 'react-dom';
.........
.........
componentDidMount() {
ReactDOM.findDOMNode(this).addEventListener('click', (event) => {
event.stopPropagation();
}, false)
}
我收到以下错误
bundle.js:45 Uncaught TypeError: Cannot read property 'findDOMNode' of undefined
答案 0 :(得分:0)
<div class="not_fixed">
this is a pretty long title
</div>
<BR>
<div class="fixed">
<span>this is a pretty long title</span>
</div>
是默认导出,导入ReactDOM
而不是findDOMNode
。
试试这个:
ReactDOM
OR
import {findDOMNode ,render, unmountComponentAtNode} from 'react-dom';
...
componentDidMount() {
findDOMNode(this).addEventListener('click', (event) => {
event.stopPropagation();
}, false)
}