I'm wondering how to clear a timeout, which is set in an onclick event in React. I'm aware you can easily cancel timeouts, when they are set in 'useEffect', but how about this use case?
export default function SomeComponent() {
const onClick = () => {
setTimeout(() => {
// dome some logic like API calls,
// which should be terminated, in case the component
// is unmounted
}, 2_500)
}
return (
<div><button onClick={onClick}>Click me!</button></div>
)
}