7.13 Cleanup Work With useEffect Example
setTimeout() setup
Cockpit.js
import React, { useEffect } from "react";
import classes from "./Cockpit.css";
const cockpit = (props) => {
useEffect(() => {
console.log("[Cockpit.js] useEffect");
// Http request...
const timer = setTimeout(() => {
alert("Saved data to cloud!");
}, 1000);
return () => {
clearTimeout(timer);
console.log("[Cockpit.js] cleanup work in useEffect");
};
}, []);
...