父類組件: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時。只有事件未定義,其他道具顯示正確我通過在子組件內創建事件并在父組件內訪問找到了解決方案,但這對我來說并不像預期的那樣有效!誰能解釋我失敗的原因。
從父母到孩子的傳遞事件反應未定義
素胚勾勒不出你
2023-05-19 17:44:36