O Codigo está funcionando sem problemas mas sempre que adiciono um novo card, ele tras o erro de key:
react-jsx-dev-runtime.development.js:87 Warning: Each child in a list should have a unique "key" prop.
Check the render method of Time
. See https://reactjs.org/link/warning-keys for more information.
at Card (http://localhost:3000/static/js/bundle.js:381:3)
at Time (http://localhost:3000/static/js/bundle.js:728:28)
at div
at App (http://localhost:3000/static/js/bundle.js:33:76)
Card.js
import './Card.css'
const Card = ({nome, cargo, imagem}) => {
return (
<div className='card'>
<div className='cabecalho'>
<img src={imagem} alt={nome}></img>
</div>
<div className='rodape'>
<h4>{nome}</h4>
<h5>{cargo}</h5>
</div>
</div>
)
}
export default Card
Time.js
import Card from '../Card'
import './Time.css'
const Time = (props) => {
const corDeFundo = {backgroundColor: props.corDeFundo}
return (
<section className='time' style={corDeFundo}>
<h3 style={{borderColor: props.corDoCard}}>{props.nome}</h3>
<div className='cards'>
{props.cards.map(card => <Card nome={card.nome} cargo={card.cargo} imagem={card.imagem}/>)}
</div>
</section>
)
}
export default Time
App.js
import { useState } from 'react';
import Banner from './componentes/Banner/Banner';
import Formulario from './componentes/Formulario';
import Time from './componentes/Time';
function App() {
const [cards, setCards] = useState([])
const times = [
{
nome:'Programação',
corDeFundo:'#D9F7E9',
corDoCard: '#57C278'
},
{
nome:'Front-End',
corDeFundo:'#E8F8FF',
corDoCard: '#82CFFA'
},
{
nome:'Data Science',
corDeFundo:'#F0F8E2',
corDoCard: 'A6D157'
},
{
nome:'Devops',
corDeFundo:'#FDE7E8',
corDoCard: '#E06B69'
},
{
nome:'UX e Design',
corDeFundo:'#FAE9F5',
corDoCard: '#DB6EBF'
},
{
nome:'Mobile',
corDeFundo:'#FFF5D9',
corDoCard: '#FFBA05'
},
{
nome:'Inovação e Gestão',
corDeFundo:'#FFEEDF',
corDoCard: '#FF8A29'
}
]
const adicionarNovoCard = (card) => {
setCards([...cards, card])
console.log(cards)
}
return (
<div className="App">
<Banner />
<Formulario cardParaAdicionar={card => adicionarNovoCard(card)} />
{times.map(time => <Time
key={time.nome}
nome={time.nome}
corDeFundo={time.corDeFundo}
corDoCard={time.corDoCard}
cards={cards.filter(card => card.time === time.nome)}
/>)}
</div>
);
}
export default App;