Dear All
I just start learning React and I have problem in using onselect event however I type my code step by step just like what is shown in the class. Does anybody know what s the problem?
Looks like a syntax error. You can’t call a function passed as a prop like that.
Try changing line 23 to:
onSelectItem={() => onSelectItem(item)}
onSelectItem() is call back to parent function on the click of button ; so it should be like this below. Hope this helps.
onClick={() => {
setSelectedIndex(index);
onSelectItem(item);
}}
Refer screenshot