React useEffect Hooks with setTimeout

0 votes

I am so confused here with React useEffect Hooks with setTimeout. 

but my code is rendering "I've rendered 2 times" instead of "I've rendered 1 time". And I have tried it in many code editors, and mine always shows 2..

My: enter image description here

And the only way I can get it to render 1 is refactoring to this instead

useEffect(() => {
     setTimeout(() => {
     setCount(count + 1);
   }, 1000);
 }, []); 

Could someone please explain to me why? Thanks for your help!

I am expecting my code to render the same result as the w3school example.

Jan 27, 2023 in Others by Tejashwini
• 3,820 points
1,041 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

Next seo test with react testing library

 you need to mock next/head, pass document.head to the container ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,600 points
2,463 views
0 votes
1 answer

Parsing a string with GetOpt::Long::GetOptions

Hey, have a look at the section ...READ MORE

answered Nov 15, 2018 in Others by nirvana
• 3,130 points
1,816 views
0 votes
1 answer

How to communicate gRPC example working with Node.js?

hi.. you can read below link, it ...READ MORE

answered Dec 2, 2019 in Others by Narendra Reddy Dalli
2,449 views
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,822 views
0 votes
1 answer

Using SharePoint designer with SharePoint Online ?

Sharepoint gives you a trial account for ...READ MORE

answered Feb 12, 2019 in Others by Priyaj
• 58,020 points
773 views
0 votes
1 answer

Execute a shell script with php

One of the possible reason for this ...READ MORE

answered Feb 24, 2019 in Others by Omkar
• 69,220 points
9,959 views
0 votes
1 answer

Why does the useEffect hook trigger twice in React?

This behavior is intentional and stems from ...READ MORE

answered Feb 12 in Node-js by Navya
40 views
0 votes
1 answer
0 votes
1 answer

Why does React's useState hook use const instead of let?

The useState Hook is typically used with ...READ MORE

answered Feb 12 in Node-js by Navya
44 views
0 votes
0 answers

Should you use MVC 2 or stick with MVC 1 for your project?

Can you tell me Should you use ...READ MORE

Feb 12 in Node-js by Nidhi
• 7,560 points
33 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP