Javascript 将事件从父级传递到子级未定义

Javascript 将事件从父级传递到子级未定义,javascript,reactjs,Javascript,Reactjs,父类组件: toggleFunction = (event, ...otherProps) => { console.log(event) // EVENT GOT UNDEFINED console.log(otherProps) // THIS IS DISPLAYING WHAT IS NEED! } <Child updateFunction={(event) => this.toggleFunction(event,"PROPS-1&quo

父类组件:

toggleFunction = (event, ...otherProps) => {
    console.log(event) // EVENT GOT UNDEFINED
    console.log(otherProps) // THIS IS DISPLAYING WHAT IS NEED!
}

<Child updateFunction={(event) => this.toggleFunction(event,"PROPS-1","PROPS-2")}>
const Child = ({ updateFunction }) => {
   ... OTHER CODE HERE
   <div onClick={() => updateFunction()}>Toggle</div>
}
toggleFunction=(事件,…其他道具)=>{
console.log(event)//未定义事件
console.log(otherProps)//这显示了需要的东西!
}
this.toggleFunction(事件,“PROPS-1”、“PROPS-2”)}>
子功能组件:

toggleFunction = (event, ...otherProps) => {
    console.log(event) // EVENT GOT UNDEFINED
    console.log(otherProps) // THIS IS DISPLAYING WHAT IS NEED!
}

<Child updateFunction={(event) => this.toggleFunction(event,"PROPS-1","PROPS-2")}>
const Child = ({ updateFunction }) => {
   ... OTHER CODE HERE
   <div onClick={() => updateFunction()}>Toggle</div>
}
constchild=({updateFunction})=>{
…这里有其他代码
updateFunction()}>切换
}
我的问题是,我在父回调中创建事件,并将其作为方法传递给子类,然后在父类中执行父toggleFunction只有事件未定义,其他道具正确显示

我通过在子组件内部创建事件并访问父组件内部找到了一个解决方案,但这对我来说并不像预期的那样有效!有人能解释一下我的失败之处吗


提前谢谢

您需要将事件从
onClick
传递到
updateFunction

<div onClick={event => updateFunction(event)}>Toggle</div>

你能发布创建事件的部分代码吗?这是回调期间创建的一个react事件我想看看什么会触发事件我不是整个函数的专家我只知道如何使用它,有些事情我不知道它是如何工作的:(对不起!我的问题是为什么其他道具显示我需要的东西,为什么只显示事件?还有其他道具?在
(event)=>this.toggleFunction(event,“Props-1”,“Props-2”)
事件
未定义(因为您调用
updateFunction
,没有参数)。其他道具没有问题,因此它们被正确地传递。为什么事件本身没有定义,为什么其他道具没有定义?
toggleFunction=(event,prop1,prop2)=>{console.log(event,props1,props2)
。在这种情况下,事件本身没有定义?