const [movies, setMovies] = useState(getMovies());
function handleLike(movie) {
const movieClone = [...movies];
const index = movieClone.indexOf(movie);
movieClone[index] = { ...movieClone[index] };
movieClone[index].like = !movieClone[index].like;
setMovies(movieClone);
}
Hi, I'm new to React and I while I was taking an online tutorial the instructor makes a clone of an object from the movies array(movieClone[index] = { ...movieClone[index] };) and I just couldn't understand why? Because when I try to run the code without cloning the object from the array it works perfectly fine.
Thank you for your time.