setVal((prevVal) => calculateNewValue(prevVal))
const calculateNewValue = (oldVal) => {
return oldVal + 1;
}
const HomePage: FC = () => {
const [val, setVal] = useState(0);
useEffect(() => {
const timeoutId = setTimeout(() => {
const newVal = calculateNewValue(val)
setVal(newVal)
}, 1000)
return () => clearTimeout(timeoutId)
}, [val])
return (
<div>
{val}
</div>
);
};