I keep getting this error while I have tried everything according to my knowledge any kind of help will be appreciated.
I try to pass the array in props then get in component and set props value in the state but when I try to map that array this error shows up:
TypeError: Cannot read property 'map' of undefined
onClick function:
const handleClickOpen = (data) => {
setOpen(true);
setPropsData(data);
};
Event handler:
onClick={() => {
handleClickOpen({
name: item.firstName,
image: item.image,
about: item.about,
id: item._id,
interests: item.intersets,
});
}}
Component passing props:
<ProfileDialog
selectedValue={propsData}
open={open}
onClose={handleClose}
/>
Component declares props like so:
const { onClose, selectedValue, interests, open } = props;
I got the error when I put in this statement:
<div>{selectedValue.interests.map((item,i) => console.log(item,i))}</div>
<div>{selectedValue?.interests.map((item,i) => console.log(item,i))}</div>