DEV Community

Discussion on: How To: Start & Stop Counter in React

Collapse
 
wsypeter profile image
siyu • Edited

why does
const current = setInterval(() => setSeconds(seconds => seconds + 1), 1000)
work but not
const current = setInterval(() => setSeconds(seconds + 1), 1000) ?
what is the difference between those two?

Collapse
 
am20dipi profile image
Adriana DiPietro

Hi Siyu! Thanks for the question. An arrow function makes an implicit return :) so we can see the incrementing of time visually on the browser page.

Collapse
 
pietow profile image
pietow

What do you mean exactly by "An arrow function makes an implicit return"?