Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i set the key in the map but unique key error still exist

<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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading