This Is Why React Prints All Console Logs Twice

Поділитися
Вставка
  • Опубліковано 9 лис 2022
  • Full Video: • This One Line Of Code ...
    Sorry about the bad audio quality. My computer changed my mic to use my webcam mic instead of my actual microphone.
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    #Shorts

КОМЕНТАРІ • 72

  • @hayesmaker64
    @hayesmaker64 Рік тому +125

    React team: We're gonna break your app to make sure your app is broken

  • @Daniel-ok7hl
    @Daniel-ok7hl Рік тому +129

    I actually read about this at work today, what a coincidence

    • @muratbock1268
      @muratbock1268 Рік тому +5

      Similar situation here, I‘ve encountered this topic at work this week

    • @gorabramyan
      @gorabramyan Рік тому +2

      What you need? Google knows better.

    • @dannnsss8034
      @dannnsss8034 Рік тому +6

      @@gorabramyan Google is too big, genius

    • @LearnCodingWithArshad
      @LearnCodingWithArshad 10 місяців тому +1

      Kinda same, except I'm looking at it from Next.js perspective. One of my co-woker was getting same thing logged two times and I was also wondering why, now I know.

  • @harmez7
    @harmez7 Рік тому +34

    indeed, its very helpful .
    back then when i was a noob i remember once i put a interval to increase a counter in a useEffect and i saw a weird behavior .
    because my component was rendering 2 times and hence i had 2 intervals to increase my counter.
    than i cleared the interval at the useEffect's cleanup function and everything went ok .

  • @KaranSethia24
    @KaranSethia24 Рік тому +3

    I recently discovered this just a few weeks ago, I was really mad why were my logs printing twice

  • @graciomlly
    @graciomlly Рік тому +8

    I noticed this twice rendering yesterday... I couldn't understand why it was happening
    Now i can 🤝🏾

  • @juanescamilla7790
    @juanescamilla7790 Рік тому +1

    Oh so, thats why My local storage saved twice when i was testing it

  • @pranishshrestha1200
    @pranishshrestha1200 Рік тому +4

    also, the mounted will only called once because of the empty dependencies.
    and if dependencies aren't passed i.e. no " ,[ ] " then the mounted will be called everytime any component render.

  • @shivagurung4161
    @shivagurung4161 Рік тому

    I searched for the answer this afternoon but to no avail. And now UA-cam recommends me this shorts.

  • @jrupp2823
    @jrupp2823 Рік тому +1

    thank you for this video kyle

  • @kehan6252
    @kehan6252 Рік тому +2

    thanks for telling, I was trying to figure if there was a bug in my code for it to console log twice

  • @marcc1179
    @marcc1179 Рік тому +2

    Every developer must understand Strict Mode:)

  • @anuvette
    @anuvette 8 місяців тому

    damn i thought my shit was rerendering twice for some reason and i was almost ready to gouge my skull

  • @brucoffee1437
    @brucoffee1437 Рік тому +1

    This was the same question on my minds

  • @devincheca9605
    @devincheca9605 Рік тому

    Good point in this video. Angular does something similar in development mode as well.

  • @piyushaggarwal5207
    @piyushaggarwal5207 Рік тому

    Great. Thanks for the depth.
    I knew about StrictMode earlier but didn't know the exact use of it. Also why it is greyed out and why it wasn't when I initially started out.

  • @mikeydflyingtoaster
    @mikeydflyingtoaster 5 місяців тому

    This is very frustrating because many tutorials have you call APIs in the App function and, now that I understand why this is happening, thanks to this video, I will be sure to look into how it SHOULD be done

  • @thePronto
    @thePronto Рік тому +1

    Been fretting about this for weeks.

  • @denvernaicker8250
    @denvernaicker8250 Рік тому

    this helped a lot thank you

  • @armaan73
    @armaan73 Рік тому

    I was new to react and i thought why was it printing all console.log 2 times. I thought it was a bug in my code. This was really helpful

  • @KCCodes
    @KCCodes Рік тому

    Thanks man. I wanted to know the reason why things were being logged 2 times for a long time.

  • @TheLittleUncanny
    @TheLittleUncanny Рік тому

    I remember tried to do prompt and it does executed twice lmao

  • @movoyemickele
    @movoyemickele Рік тому +1

    He always refers to look at the comments, but nothing can be found here. I wonder if he sells any courses. Since the material is good, I’ll be happy to join even though I’m already a react programmer.

  • @nested9301
    @nested9301 Рік тому +2

    React has alot of nasty code under the hood . I see the future of elm and functional programming in general

  • @ControlAllDa1337
    @ControlAllDa1337 Рік тому

    You are kidding me, I've spent ages wondering why my app seemed to running code multiple times and couldn't figure it out. Sure enough, my app component is wrapped in a ScrictMode tag

  • @mindbodyps
    @mindbodyps Рік тому

    Beginner who console log to check in dev tool is data coming from api : OMG 😱

  • @shawn-skull
    @shawn-skull Рік тому +1

    Why should I never declare an external variable, if it looks to work here.

  • @OUSSAMA-ob1dk
    @OUSSAMA-ob1dk Рік тому

    thanks

  • @i_am_daim
    @i_am_daim Рік тому

    THANK YOU! 👍

  • @alext5497
    @alext5497 Рік тому +5

    Thank God you didn't recommend turning it off.

  • @INAVACL
    @INAVACL Рік тому

    THANK YOU

  • @anshulnamdev9363
    @anshulnamdev9363 Рік тому

    Damn u are soo good at this , this helps me a lot thanks!!!

  • @srinivassr5067
    @srinivassr5067 Рік тому +1

    What's the font style that u r using in this video

  • @nicoloteseo2414
    @nicoloteseo2414 Рік тому

    very helpful

  • @p1k1m4ru
    @p1k1m4ru Рік тому

    best guy on youtube

  • @carlandres3319
    @carlandres3319 10 місяців тому

    Dude, can you make a video of tricks with URL fragments? 🙏🙏🙏

  • @gabriellavarinimoreira9760
    @gabriellavarinimoreira9760 Рік тому

    Thaks!!!

  • @user-rt6fq8wk1d
    @user-rt6fq8wk1d Рік тому +2

    "It's just bad code in general" lol savage

  • @cristoferrao8937
    @cristoferrao8937 10 місяців тому

    hi, is there a way to direct print to print like default print without showing pdf or any for like restaurants. and print at multiple printer at same time

  • @abuzarmahmood5179
    @abuzarmahmood5179 Рік тому

    I want to ask why when an error occurs in react error message is displayed twice on console and even getDerivedStateFromError() life cycle method runs twice.

  • @its_vincesanity
    @its_vincesanity Рік тому +2

    React always feels broken, not even angular.js (Angular 1) was that funky.

    • @limitlessmaster659
      @limitlessmaster659 Рік тому +1

      Just go Vue and you'll never go back

    • @Dev-Siri
      @Dev-Siri Рік тому

      It's supposed to be helpful for beginners.
      You can always disable strict mode and the funkiness in development will stop.

  • @InMemoryOfNeo
    @InMemoryOfNeo Рік тому

    is there an alternative for react.strick mode? bcs this is making me angry at the development time. I really don't want to double rendering.

  • @fifty6737
    @fifty6737 Рік тому +6

    everything in react behave weirdly, nothing is clear, nothing is explicit or well documented or behave like you think it should behave, react is both genius and pure fucking insanity at the same time

    • @gethermedel3620
      @gethermedel3620 Рік тому +1

      that is why I stay away from it, it's the worst of the 3 dogs

  • @jackykwan6534
    @jackykwan6534 Рік тому

    it come when react 18 launch

  • @dhawalparmar7117
    @dhawalparmar7117 Рік тому

    Why axios sent request twice, one is our regular request and other is request with option method

  • @oguzhan2393
    @oguzhan2393 Рік тому

    then what is the solution for this? didnt get it.

  • @thetech3624
    @thetech3624 Рік тому +2

    So then how do you stop the double rendering for some things while keeping strict mode? Or do you have no choice but to remove strict mode?

    • @arakwar
      @arakwar Рік тому

      Once you compile for production strict mode stop the double render.
      It’s useful for you in dev, it’s simulating an upcoming React breaking change. Fix your code.

  • @littleshorts6969
    @littleshorts6969 Рік тому

    Plz answer this :- Why is using 'renderCount' variable is deprecated by him ?

    • @avidrucker
      @avidrucker Рік тому

      Global state is something that can lead to a lot of problems in applications. There are some exceptions to this general rule though, such as a GaneState object in game development, where using global state can be helpful/effective.

  • @Dev-vs5kb
    @Dev-vs5kb Рік тому

    Already knew it✌️

  • @Dylan_thebrand_slayer_Mulveiny

    "Its not a bug, it's a feature". Having your components run twice unexpectedly with 0 explanation, ONLY in dev mode is absurd.
    More proof react is a hot pile of garbage.

    • @Dylan_thebrand_slayer_Mulveiny
      @Dylan_thebrand_slayer_Mulveiny Рік тому

      @avfr Care to elaborate on what edge cases you're referring to?

    • @Dylan_thebrand_slayer_Mulveiny
      @Dylan_thebrand_slayer_Mulveiny Рік тому

      @avfr Okay, I guess that makes sense. It would also force you to unhook event listeners to prevent memory leaks.
      It still seems bizarre that it would force this behavior.

  • @Kedi211_
    @Kedi211_ Рік тому +2

    You can’t be a dev looking this good 😂❤

  • @knuseski
    @knuseski Рік тому

    And what is the solution?

    • @feritperliare2890
      @feritperliare2890 Рік тому +1

      Ignore it hope that it doesn’t happen in production and starting to consider other frameworks that doesn’t decide to double your code runtime or worst fucking up checking how many api requests go out

  • @andrwondabeat
    @andrwondabeat Рік тому

    i cant hear you man turn up ur microphone

  • @gethermedel3620
    @gethermedel3620 Рік тому

    React is still over-hyped for me, I've used all 3 big dogs to create a medium complex application, and I have to say React is the worst to work with.

  • @dailyMoodStation
    @dailyMoodStation Рік тому

    Hello, thank you for your tutorials, but can you speak slowly, please!

  • @michaelocenar6140
    @michaelocenar6140 Рік тому

    Why no semicolons? :(

  • @fancybeing1296
    @fancybeing1296 Рік тому

    Hatts of to this man, he is god for me , he provide me free amazing knowledge when I can't afford a paid course ,thank u so much