Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.69 KB

File metadata and controls

28 lines (19 loc) · 1.69 KB

useEffect + Macro/Micro Tasks medium #react

by Pawan Kumar @jsartisan

Take the Challenge

What will be the output in console for the following code:

function App() {
  const [state] = useState(0)
  console.log(1)
  
  const start = Date.now()
  while (Date.now() - start < 50) {
    window.timestamp = Date.now()
  }
  
  useEffect(() => {
    console.log(2)
  }, [state])

  Promise.resolve().then(() => console.log(3))

  setTimeout(() => console.log(4), 0)

  return null
}

Back Share your Solutions Check out Solutions