I need to pass a handler method from the parent component to the list item so that it can be invoked when the checkbox is checked/unchecked. I tried to pass the method as a prop to the listview component but it doesn’t seem to relay it to the list items.
Uncaught TypeError: Cannot read property 'myCustomHandler' of undefined
at onChange (ShoppingIngredients.page.js:18)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306)
at executeDispatch (react-dom.development.js:389)
at executeDispatchesInOrder (react-dom.development.js:414)
at executeDispatchesAndRelease (react-dom.development.js:3278)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3287)
at Array.forEach (<anonymous>)
at forEachAccumulated (react-dom.development.js:3257)
at runEventsInBatch (react-dom.development.js:3304)
at runExtractedPluginEventsInBatch (react-dom.development.js:3514)
at handleTopLevel (react-dom.development.js:3558)
at batchedEventUpdates$1 (react-dom.development.js:21871)
at batchedEventUpdates (react-dom.development.js:795)
at dispatchEventForLegacyPluginEventSystem (react-dom.development.js:3568)
at attemptToDispatchEvent (react-dom.development.js:4267)
at dispatchEvent (react-dom.development.js:4189)
at unstable_runWithPriority (scheduler.development.js:653)
at runWithPriority$1 (react-dom.development.js:11039)
at discreteUpdates$1 (react-dom.development.js:21887)
at discreteUpdates (react-dom.development.js:806)
at dispatchDiscreteEvent (react-dom.development.js:4168)
Maybe it’s an issue with how I’m referencing myProps on the ListItem side i.e. ’ this.props.myProps.myCustomHandler()’.
Would it be possible to point to a javascript example for the same or some documentation on itemProps param ?
This error is caused by the problem that in the ListItem class you referred to the myCustomHandler function, as follows: this.props.myProps.myCustomHandler. In this case, you don’t need to use the myProps key, because you passed it from the parent class.
You need to use it like this: this.props.myCustomHandler()