AI

Closures in JavaScript capture variables at the time they are created. In React, this means setTimeout or event listeners might see 'old' state values if you're not careful.

Your Task:

  • Fix the DelayedLogger component
  • The user clicks 'Start Log' (count is 0), then clicks 'Increment' 5 times (count is 5)
  • But when the log fires, it prints 'Count: 0'!
  • Update the code to ensure it sees the current count, possibly using useRef
TypeScript Solution
Loading...

Submit your code to see test results