Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
React.js - Unique "Key" prop when updating

When I load my page, eveything is fine. When a new show is added, the error appears. Every has a key, I searched all the questions and blogs but can't get it right!

ShowsDisplay.js

import styles from "./ShowsDisplay.module.css";

function ShowsDisplay ({shows, deleteShow}) {
    if (shows.length === 0) {
        return (
            <div key={"nenhumshow"}>
                <p>Nenhum show listado</p>
            </div>
        );
    }
    return (
        <div key={"showsencontrados"}>
            {shows.map((show) => {
                return (
                    <div key={show.id} className={styles.showsDisplay}>
                        <p className={styles.showsTitles}> {show.title}</p>
                        <button className={styles.deleteButton} type="button" onClick={ () => deleteShow(show) }>Delete</button>
                    </div>
                );
            })}
        </div>
    );
}


export default ShowsDisplay;

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try making key as much unique for each child element as you can . Key is the property which tells React DOM , which child element is updated/deleted/added .

{shows.map((show,index) => {
                return (
                    <div key={show.id+" "+ index} className={styles.showsDisplay}>
                        <p className={styles.showsTitles}> {show.title}</p>
                        <button className={styles.deleteButton} type="button" onClick={ () => deleteShow(show) }>Delete</button>
                    </div>
                );
            })}
about 4 years ago · Juan Pablo Isaza Relatório

0

It must be about the new show, probably the new show's id is undefined so you get that error

if your id is not number in a row try this

{shows.map((show,index) => {
                return (
                    <div key={show.id??index} className={styles.showsDisplay}>
                        <p className={styles.showsTitles}> {show.title}</p>
                        <button className={styles.deleteButton} type="button" onClick={ () => deleteShow(show) }>Delete</button>
                    </div>
                );
            })}

Or just this ''

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda