I have the array with ids
const [selected, setSelected] = React.useState<readonly string[]>([]);
var selectedId = props.selectedId;
When clicking on the clean button I have added a useState() which check the given selectedId has a value or not If selectedId has a value then add a value in array, if not then remove all the elements from the array
useEffect(() => {
if (selectedId != undefined) {
// Add selectedId in selectedIdsList
setSelected(selectedId)
} else {
// remove all elements from setSelected
}
}, [selectedId]);
How to delete all elements from array
selectedIdsListisn't array it is objectselectedIdsList = []but since you are using state you can set it something like this =setSelected([])