setimeout react button

Solutions on MaxInterview for setimeout react button by the best coders in the world

showing results for - "setimeout react button"
Anton
22 May 2016
1import React, { useEffect, useState } from 'react';
2
3const TimeoutExample = () => {
4  const [count, setCount] = useState(0);
5  const [countInTimeout, setCountInTimeout] = useState(0);
6
7  useEffect(() => {
8    setTimeout(() => {
9      setCountInTimeout(count); // count is 0 here
10    }, 3000);
11    setCount(5); // Update count to be 5 after timeout is scheduled
12  }, []);
13
14  return (
15    <div>
16      Count: {count}
17      <br />
18      setTimeout Count: {countInTimeout}
19    </div>
20  );
21};
22
23export default TimeoutExample;
24