useRef()
Pozwala na tworzenie "zmiennych instancji"
function CancellableTimeout(callback) {
const timeoutRef = useRef();
useEffect(() => {
timeoutRef.current = setTimeout(callback, 15000);
return () => { clearTimeout(timeoutRef.current); }
})
return (
clearTimeout(timeoutRef.current)}>Cancel timeout
)
}