<MenuList width={'148px'} >
{ Object.entries(userRoleMenu[UserRole]).map((item, index) => <>
{item[0]==='fpv?
<MenuItem _hover={{backgroundColor:'gray.50'}} key={item[0]} onClick={handleMenuClick(item)}>
</MenuItem>
:
<MenuItem _hover={{backgroundColor:'gray.50'}} key={item[0]} onClick={handleMenuClick(item)}>{item[0]}</MenuItem>
}
</>)
}
</MenuList>
error:
UserProfileThumbnailMenuList.tsx:65 Warning: Each child in a list should have a unique "key" prop.
Check the render method of UserProfileThumbnailMenuList. See https://reactjs.org/link/warning-keys for more information.
at UserProfileThumbnailMenuList
code is in UserProfileThumbnailMenuList
i dont know why unique key error still exist
>Solution :
<MenuList width={'148px'}>
{Object.entries(userRoleMenu[UserRole]).map((item, index) => (
<React.Fragment key={item[0]}>
{item[0] === 'fpv' ? (
<MenuItem _hover={{ backgroundColor: 'gray.50' }} onClick={() => handleMenuClick(item)}>
{/* Add content for the fpv case here */}
</MenuItem>
) : (
<MenuItem _hover={{ backgroundColor: 'gray.50' }} onClick={() => handleMenuClick(item)}>
{item[0]}
</MenuItem>
)}
</React.Fragment>
))}
</MenuList>
I’ve added the correct key prop to the React.Fragment, and I’ve also fixed the syntax error in the conditional check by changing {item[0]===’fpv? to {item[0]===’fpv’ ?. Make sure to replace the placeholder comment with the actual content for the fpv case inside the MenuItem.