Bro I'm an experienced react dev so I already know most of the stuff you talk about. But you are probably the best coding TH-camr on the platform, no yelling mild takes, not pushing an agenda, just clean, precise and interesting content. Keep it up!
That probably explains why I get the api calls with react query running twice on mount, good thing I started using the signal to abort the request on cleanup. I was aware of React's strict mode, but never understood it correctly, this video made it very clear, thank you! And I think strict mode is a must, very useful.
Love the video and your production style! Learned some good stuff here. (It could have been slightly higher pace or shorter, but otherwise really good!)
Thanks! I often misunderstand the whole concept of strict mode. One time I was fetching the data multiple times and end up wasting 1 day only to find out it was happening bcz of the strict mode tho:)
Sheesh this was really great! I knew about the "cleanup" return function in useEffect, but I have probably done that mistake 100 times in my apps, and never noticed 😅 Also - the backlight doubling as practical light in the background is 🧑🍳😘
I’ve always enjoyed your streams while you’re working on Mirage. When I get a notification for a new video from you, I get really excited, and you never disappoint. Keep on going! Your videos are insanely good. Quality content, superb delivery. Only a if you make them more often.
The proper way to implement this is to instead use setTimeout and add count as a dependency, so that when count is updated it restarts the timeout. setInterval should never be used as it does not guarantee execution if the inner function takes longer than the interval. (there are other issues with setInterval as well - can google it for more info)
The logic is "increase the count by 1 every second" - that's an interval. You don't want to use count as a dependency to achieve this behavior for two reasons: first, it's literally not a dependency when using the function version of setState, and second (and more importantly), count could change for reasons other than the interval increasing it. (If you wanted different logic based on count changing for other reasons, that would also be achievable, but it's a different requirement.) I'm not sure I understand your point about "the inner function taking longer than the interval". The inner function here is just a call to setState and is not asynchronous code, and it would be the same if it were in a timeout. You can absolutely use setInterval in React applications. There do exist libraries like useInterval which offer more functionality, but they ultimately are more sophisticated wrappers around setInterval. (And no criticism taken, I welcome the questions!)
React Strict mode simple replaces a "maybe" bug with a "certain" but which noob/blind devs might miss and therefore introduce bugs into the system. Strict mode is a big no-no for me, for years. It's catastrophic.
Bro I'm an experienced react dev so I already know most of the stuff you talk about. But you are probably the best coding TH-camr on the platform, no yelling mild takes, not pushing an agenda, just clean, precise and interesting content. Keep it up!
I've met him in person... he's like this in person as well. Very down to earth
Really appreciate this message 😊 👊
he has baraka in him lol
As a react rookie, I appreciate the breakdown
That probably explains why I get the api calls with react query running twice on mount, good thing I started using the signal to abort the request on cleanup.
I was aware of React's strict mode, but never understood it correctly, this video made it very clear, thank you!
And I think strict mode is a must, very useful.
bro why are you so good in teaching?! Its abnormal that I'm able to grasp every single word that comes out of your mouth!
Love the video and your production style! Learned some good stuff here. (It could have been slightly higher pace or shorter, but otherwise really good!)
The way you talk is really awesome man!! And I never heard about chaos monkey. Thanks
Thanks! I often misunderstand the whole concept of strict mode. One time I was fetching the data multiple times and end up wasting 1 day only to find out it was happening bcz of the strict mode tho:)
Your vim chops are smooth..
I’ve also got into it last month
That's vscode bro
@@pablozuta2402 yeah but he's clearly using vim bindings
Best investment you’ll ever make!
Sheesh this was really great! I knew about the "cleanup" return function in useEffect, but I have probably done that mistake 100 times in my apps, and never noticed 😅 Also - the backlight doubling as practical light in the background is 🧑🍳😘
I’ve always enjoyed your streams while you’re working on Mirage. When I get a notification for a new video from you, I get really excited, and you never disappoint. Keep on going! Your videos are insanely good. Quality content, superb delivery. Only a if you make them more often.
This is great! Thank you so much for this breakdown! 🙏
The proper way to implement this is to instead use setTimeout and add count as a dependency, so that when count is updated it restarts the timeout. setInterval should never be used as it does not guarantee execution if the inner function takes longer than the interval. (there are other issues with setInterval as well - can google it for more info)
Also, I'm not being critical of your content. I know it wasn't the point of this video. Keep it coming!
The logic is "increase the count by 1 every second" - that's an interval. You don't want to use count as a dependency to achieve this behavior for two reasons: first, it's literally not a dependency when using the function version of setState, and second (and more importantly), count could change for reasons other than the interval increasing it. (If you wanted different logic based on count changing for other reasons, that would also be achievable, but it's a different requirement.)
I'm not sure I understand your point about "the inner function taking longer than the interval". The inner function here is just a call to setState and is not asynchronous code, and it would be the same if it were in a timeout. You can absolutely use setInterval in React applications. There do exist libraries like useInterval which offer more functionality, but they ultimately are more sophisticated wrappers around setInterval.
(And no criticism taken, I welcome the questions!)
Awesome explanation! Thanks man
React Strict Mode white background blinded me, now I sing about just calling someone and saying I love you.
The production value of this video is so high. Damn man, even down to that exceptionally groomed beard 😂 You're basically the Wenger of dev content!
Thanks a lot
Thx
For me most of the time is i dont get errors with strict mode in dev but when in Prod then i start getting issues
this is completely broken when you try to use refs
React Strict mode simple replaces a "maybe" bug with a "certain" but which noob/blind devs might miss
and therefore introduce bugs into the system. Strict mode is a big no-no for me, for years. It's catastrophic.
Why was this in my recommended? lmao im not close to be a programer xD cool explanation tho 👍