Reactjs 将父项作为参数传递给子项';s合成事件 类MakeRotate扩展了React.Component{ rectMOuseDown=(e,/*想要父级g在这里*/)=>{ /*我必须在这个函数中对g做一些运算*/ } render(){ 返回( this.rectMOuseDown(e,/*wana传递父级g*/)}> ) } }

Reactjs 将父项作为参数传递给子项';s合成事件 类MakeRotate扩展了React.Component{ rectMOuseDown=(e,/*想要父级g在这里*/)=>{ /*我必须在这个函数中对g做一些运算*/ } render(){ 返回( this.rectMOuseDown(e,/*wana传递父级g*/)}> ) } },reactjs,svg,Reactjs,Svg,我不想使用ref概念。因为在我的代码中,g在循环中生成。所以不能将同一个ref分配给所有g。react中是否有任何概念,以便我可以将整个g传递到Is child的合成事件函数中。您可以使用JavascriptcurrentEvent并从那里开始? 例如 onMouseDown={e=>console.log(e.currentTarget.parentNode)} 或者你有不同的用例吗 Class MakeRotate extends React.Component { rectMOuse

我不想使用ref概念。因为在我的代码中,g在循环中生成。所以不能将同一个ref分配给所有g。react中是否有任何概念,以便我可以将整个g传递到Is child的合成事件函数中。

您可以使用Javascript
currentEvent
并从那里开始? 例如
onMouseDown={e=>console.log(e.currentTarget.parentNode)}
或者你有不同的用例吗

Class MakeRotate extends React.Component {
  rectMOuseDown = (e, /* want the parent g here*/) => {
    /* I have to do some operation on g inside this function */
  }
  render() {
    return (
      <div>
         <g className="some-class" transform="translate(40,40) rotate(0, 240, 80)">
            <rect x="0" y="0" width="60" height="60" onMOuseDown={e => 
            this.rectMOuseDown(e, /*wana to pass parent g*/)}>
         </g>
      </div>
    )
  }
}