xxxxxxxxxx
// Use the filter method
setState(crt => {
return crt.filter((_el, index) => (index !== idx))
})
xxxxxxxxxx
const [ratings, setRatings] = useState([]);
const ratingHandler = (value) => {
// Create a copy of the ratings array
let newArray = [ratings];
const index = newArray.indexOf(value);
if (index !== -1) {
// Item exists, remove it
newArray.splice(index, 1);
} else {
// Item doesn't exist, add it
newArray.push(value);
}
// Update state with the new array
setRatings(newArray);
};