I have a variable id that has already had value, I just want that if the user click the ClearIcon the id will turn to null. so that he does not become equal to location.id
const [getId, setId] = useState(id)
const stopSearching = () => {
setId(null)
};
<IconButton onClick={stopSearching} edge="end">
<ClearIcon />
</IconButton>
{console.log(getId)}
{filteredLocations.map((location, index) => (
<LocationWidgetItem
key={index}
location={location}
onClickLocation={setActiveLocation}
selectedLocation={location.id ==getId}
/>
))}
onClickis being handled bystopSearchbut the handler/function you defined isstopSearching, is it just a typo in question? if not make sure that both have the same name. Also setidtonullin thestopSearchfunction.location.id ==getId) It was probably getting undefined because in your useState as I meantioned above you set the initial value toidwhich is probaly a variable that you haven't decalred