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

My console are screaming about the React KEY but I didn't see the error. Can you help me?

I see this warning in console. But where is my mistake? I have Warning: Each child in a list should have a unique "key" prop. but I put the KEY PROP in all components what I render with map function.

One warning in this map function:

{data && data.map(item => (
              <Card key={item.id}>
                <CardTitle>{item.title}</CardTitle>
                <CardPrice>{item.price}</CardPrice>
                <CardDescription>{item.description}</CardDescription>

                <CardItems>

                  {item.benefits.map(benefitsItem => (
                    <CardItem>
                      <CheckCircleIcon />
                      <CardItemText>{benefitsItem}</CardItemText>
                    </CardItem>
                  ))}
                  
                </CardItems>
                
                <StyledPopup
                    trigger={<CardButton className="BlackButton">Замовити сайт</CardButton>}
                    modal
                    nested
                    lockScroll
                >
                {close => (
                    <div className='modal'>
                        <button className="closeModal" onClick={close}>&times;</button>
                        <Feedback
                          isPlan={{
                            name: item.title,
                            description: item.description,
                            price: item.price
                          }}
                        />
                    </div>
                )}
                </StyledPopup>
                
              </Card>
            ))}

And Other warning in this component:

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

<Navigation>
   {cards && cards.map(item => renderLinks(item))}
</Navigation>

<CardsWrapper>
   {cards && cards.map(item => renderCard(item))}
</CardsWrapper>

There is the render functions.

const renderCard = (cardData) => {
        
        if(cardData.cardId === activeCard){
            return(
                <Card key={cardData.cardId}>
                    <ImageWrapper>
                        <Image src={cardData.cardImage} />
                    </ImageWrapper>

                    <CardInfoWrapper>
                        <CardTitle>{cardData.cardTitle}</CardTitle>

                        <CardDescription>
                            {cardData.cardDescription}
                        </CardDescription>

                        <Pluses>

                            {cardData.cardOpportunities && cardData.cardOpportunities.map(opportunity => (
                                <Plus>
                                    <Ok><CheckCircleIcon /></Ok>
                                    {opportunity}
                                </Plus>
                            ))}

                        </Pluses>
                    </CardInfoWrapper>
                </Card>
            )
        }
    }

And finnely

const renderLinks = (cardData) => {

        if(cardData.cardId === activeCard) {
            return(
                <div key={cardData.cardId}>
                    <NavigationItem
                        className="navigationLink"
                        width={cardData.cardLinkWidth}
                        active
                    >
                        {cardData.cardLink}
                    </NavigationItem>
                </div>
            )
        } else {
            return(
                <div key={cardData.cardId}>
                    <NavigationItem
                        className="navigationLink" 
                         width={cardData.cardLinkWidth}
                        onClick={() => linkClickHandler(cardData.cardId)}
                    >{cardData.cardLink}</NavigationItem>
                </div>
            )
        }
    }

>Solution :

Looks like there’s a missing key prop on line 10 at

{item.benefits.map(benefitsItem => (
  <CardItem>

CardItem needs a key prop.

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