我正在制作并监听正常的DOM CustomEvent
与父节点进行通信:
在孩子:
var moveEvent = new CustomEvent('the-graph-group-move', {
detail: {
nodes: this.props.nodes,
x: deltaX,
y: deltaY
},
bubbles: true
});
this.getDOMNode().dispatchEvent(moveEvent);
Run Code Online (Sandbox Code Playgroud)
在父母:
componentDidMount: function () {
this.getDOMNode().addEventListener("the-graph-group-move", this.moveGroup);
},
Run Code Online (Sandbox Code Playgroud)
这有效,但有一种特定于React的方式会更好吗?
reactjs ×1