here's the code
funtion App(){
const [Cards, setCards] = useState([
{id: 0 , name: 'Harry Potter'},
{id: 1 , name: 'Hermonie Granger'},
{id: 2 , name: 'Ron Weasly'},])
const shuffle = (arr)=>{
// just shuffle the arr then return it.
}
return (
<div className="App">
<div>{Cards[0].name}</div>
<button onClick={() => {
setCards([...shuffle(Cards)])
console.log(Cards)
}}>Testing</button>
</div>
);
}
why did this works setCards([...shuffle(Cards)])
and not this setCards(shuffle(Cards))
.
Even if i dont use the spread operator it shuffles the cards (see in console) but not displaying it in the page.
:) ;) ....