This One Line Of Code Catches React Bugs For You

  Рет қаралды 59,550

Web Dev Simplified

Web Dev Simplified

Күн бұрын

Пікірлер: 61
@matiasvaldez370
@matiasvaldez370 Жыл бұрын
Amazing video! Would love to see one about react server components explained by you 😁
@jpisello
@jpisello Жыл бұрын
Now I finally understand why my components mount/unmount/mount!
@amit.pawase007
@amit.pawase007 Жыл бұрын
As a web developer, I feel that I need to focus on react internals more than on business logic. 😢
@harag9
@harag9 Жыл бұрын
on the useEffect running twice issue - isn't that then going run my fetch commands twice in development mode? just like it's creating the eventlisten twice (then removing the 1st one), how do we do this when we use .fetch to get data from the API in useEffect?
@Ayomikun
@Ayomikun Жыл бұрын
Thanks Kyle, great video as always. I am a little confused / unsure about a couple of things though. In that first example with the reducer. If the toggle admin gets triggered twice, then surely the isAdmin state would never change? As isAdmin = !isAdmin gets called twice? Also, with the use effect example, are we now just supposed to accept that the effect runs twice, and you see that console log twice? What if instead we were logging out to a file, or communicating with an API, we'd just have to do those actions twice every time? Feels a little... off Thanks
@WebDevCody
@WebDevCody Жыл бұрын
It only runs twice in dev mode, not with a production build, so it isn’t a real issue with two api requests. If you write your cleanup effect correctly you should cancel the original api request using an abort controller on effect clean up.
@Ayomikun
@Ayomikun Жыл бұрын
@@WebDevCody Thanks for getting back to me on that Cody. Yeah I was thinking the abort controller might be the answer, but I guess the file logging example still stands. Would be annoying to have all those log messages written to a file twice even in a dev environment. Fan of your videos too. Thought I had my head around useEffect a while back but just went to debug some code I wrote a couple months ago and realised I made a real mess of it! 😄
@WebDevCody
@WebDevCody Жыл бұрын
@@Ayomikun I still don’t have my head wrapped around use effect 😢
@hexada_ghostemane
@hexada_ghostemane Жыл бұрын
do you recommend DeepScan visual studio code-extension?
@EnglishRain
@EnglishRain Жыл бұрын
I used to always delete StrictMode lines lol
@benyamin4634
@benyamin4634 Жыл бұрын
thanks
@thupilcharwaka
@thupilcharwaka Жыл бұрын
Foes this work of React Native app also ?
@DEV_XO
@DEV_XO Жыл бұрын
Amazing mate! Thanks!
@noredine
@noredine Жыл бұрын
Is it safe to say that strict mode code is compatible with non-strict mode, but not vice versa?
@NubeBuster
@NubeBuster Жыл бұрын
well, if your code is good then its cross compatible. But non strict code is always compatible with strict code
@augustine_codes
@augustine_codes Жыл бұрын
How can the issue of having unintended side effects be fixed? What can be done to avoid functions running twice?
@NIronwolf
@NIronwolf Жыл бұрын
Running them twice is the point. However you're processing it should end up in the same place even if it is run twice. This is guarding against future versions of React that may break things up differently and things may run at different times, so it all needs to come to the same result.
@augustine_codes
@augustine_codes Жыл бұрын
@@NIronwolf hmm. So how can we return the same result when it run twice. Using the first example. I understand using cleanups in the useEffect hook
@guanbo-yang
@guanbo-yang Жыл бұрын
You can write a custom hook that runs effects only once even in strict mode, if you really need to do that
@NIronwolf
@NIronwolf Жыл бұрын
@@augustine_codes using globals in a component has always been a poor practice from how I understand it. Changing state should be done through passing props or adding something like Redux. I'm sorry I can't be more clear, I'm also learning this stuff. 🙂
@Yurusaii
@Yurusaii Жыл бұрын
hey, web simplified. I have a favor, can you please make an tutorial about how to convert big numbers into like this 1e^6 it's for my project game and I don't know how to do it here's the problem in my game the problem is if the number reached 100 trillion the space in the screen will get overlapped and I don't know how to fix it, i just wanted if it reaches 10-50trillion it should've been like 1e^13 it doesn't give the code i want can you please do an tutorial on it, Thank's! my game is clicking game, and i am on mobile, if you ask.
@josemaker5252
@josemaker5252 Жыл бұрын
This is called "scientific notation". It shouldn't be too hard to find a tutorial to create a function that does just this
@appledore
@appledore Жыл бұрын
Nice educative video about strict mode. I had a doubt about it however, hopefully someone can help me out clear it. So, I basically remove strict mode in every project because it sends duplicate API requests. I’m calling those requests via async await event handlers on events like click and what not. So am I doing it correctly or should I implement some sort of logic to cancel (like clean up) sent requests? I’m relatively new at react so I would appreciate any help clearing this. Thanks in advance.
@jak3legacy
@jak3legacy Жыл бұрын
No; the point of sending duplicate API requests is that having an api request called upon component mount is an anti-pattern. Anything that you need to turn off Strict Mode to resolve is an anti-pattern.
@appledore
@appledore Жыл бұрын
@@jak3legacy Ohhhh, got it. Thanks mate I understand. But wait. I'm only sending (executing the code) the request upon a click of a button (for example) and still its sending the request two times. Does that mean that when the component is mounted it executes my event handler function? That doesn't make sense. Have you ever experienced this? Oh and BTW, I'm using functional components (just FYI). A stackoverflow post mentioned that the strict mode renders the DOM twice. So for every click it'll render that click twice and that's why my click handler function is being executed twice and the request's been sent twice. IDK 🤷‍♂WEIRD!
@WebDevCody
@WebDevCody Жыл бұрын
@@jak3legacy idk if fetching data on mount is an anti pattern… you’ll need to fetch the data somewhere, so it’s either you listen for router change events and make the api request or you fetch the initial page data when a page / component mounts.
@alexandranikolaieva8119
@alexandranikolaieva8119 Жыл бұрын
@@appledore seems to be an old comment, but i came here because of the same question in my mind) did you find the answer? What is the right way to avoid duplicated request on click event handler with strictMode? 🤔
@appledore
@appledore Жыл бұрын
@@alexandranikolaieva8119 no worries. What I found was, that strict mode is designed and used to do that exact same thing. So, if you want to avoid duplicated requests - remove strict mode, else just keep it - it’s not an issue or bad code design. When you build your project anyways, it’ll remove strict mode functionality i.e., it’ll send a single request in production environment. Hope this helps.
@adam_la_morre
@adam_la_morre Жыл бұрын
Can you please do a hair-styling tutorial? Guaranteed to get over 1 billion views 👍
@coleogden907
@coleogden907 Жыл бұрын
Hey kyle could you simplify deployment of MERN web app on AWS..? Okay cool 👍
@flamakespark
@flamakespark Жыл бұрын
🔥
@navjotsingh2457
@navjotsingh2457 Жыл бұрын
@freespeech515
@freespeech515 Жыл бұрын
Can u make react video in 30min. Very basics. Why people call it reducer. As thought its some big magic. Bad naming convention
@shreyasnair02
@shreyasnair02 Жыл бұрын
Wait what, i thought all react apps are in strict mode by default? Because all type module files are in strict mode by default and react app has strict mode for all. What? Im lost, can someone help
@intoTheEther1
@intoTheEther1 Жыл бұрын
You are right.
@shreyasnair02
@shreyasnair02 Жыл бұрын
@@intoTheEther1 then why is he manually writing react.strictmode? If it's enabled by default, why does he need to write that?
@mr.actapus4069
@mr.actapus4069 Жыл бұрын
@@shreyasnair02 Because some people delete it without knowing what it does like I did in past because it used to log messages 2X time
@intoTheEther1
@intoTheEther1 Жыл бұрын
@@shreyasnair02 Some people may be setting up their React app without strict mode since it is an option if you manually select your options in Create React App(if I recall correctly). I would recommend Vite over CRA anyway. Simple and more performant.
@inakiarias7465
@inakiarias7465 Жыл бұрын
You are confusing JavaScript's strict mode with React.StrictMode component, they are completely different things
@DanZ-fq2qs
@DanZ-fq2qs Жыл бұрын
does anyone actually keep this in development ??? its so confusing and I don't find it helpful.
@iamacoder8331
@iamacoder8331 Жыл бұрын
React is bullshit, I don't quite get it why people use it. I think only because of marketing, sad.
@jordanleon9201
@jordanleon9201 Жыл бұрын
its BS but im getting this money though BUAHAHAHAHA
@mohammadmedo5114
@mohammadmedo5114 Жыл бұрын
One
@AbdurrahmanASUR
@AbdurrahmanASUR Жыл бұрын
ربحت ايفون 69 برو ماكس لانك اول تعليق
@rishiraj2548
@rishiraj2548 Жыл бұрын
Yes, I knew
@EliKennedy
@EliKennedy Жыл бұрын
Oh man I was wondering why my log statements started doubling
@rishiraj2548
@rishiraj2548 Жыл бұрын
👍👍
@TRIC4pitator
@TRIC4pitator Жыл бұрын
oh damn , didn't know React had also strict mode
@CTILET
@CTILET Жыл бұрын
Cool
@IkeVoodoo
@IkeVoodoo Жыл бұрын
I don't use react, but this is really nice to watch!
@brabenetz
@brabenetz Жыл бұрын
True, when I see how messed up react is, I'm very happy with angular....
@mr.actapus4069
@mr.actapus4069 Жыл бұрын
@@brabenetz How is it messed up
@IvanRandomDude
@IvanRandomDude Жыл бұрын
So I am not the only one. I am not even FE developer. I just watch this video to understand clients who fetch my APIs better
@brabenetz
@brabenetz Жыл бұрын
@@mr.actapus4069 for the start: You need a useState(...) for having a variable which can be changed. There is no dependency-injection. Instead there are this complex patterns with state, reducers, actions, side-effects. It feels for me that useState(...) is a workaround for missing ChangeDetection and redux & redux-saga is a workaround for missing dependency-injection & RxJS.
@tuananhdo1870
@tuananhdo1870 Жыл бұрын
@@brabenetz you are living in ice age, sorry. If you not knowing react, what you even doing
@atsglobalservices6136
@atsglobalservices6136 Жыл бұрын
react is overrated
@fadfooood
@fadfooood Жыл бұрын
Let me guess. You don’t excel in it.
@lazycyclone
@lazycyclone Жыл бұрын
do you have 5 years of experience in writing javascript?
@atsglobalservices6136
@atsglobalservices6136 Жыл бұрын
@@lazycyclone 4 years
This Is A Great Beginner React/TypeScript Project
44:25
Web Dev Simplified
Рет қаралды 127 М.
Array Methods in JavaScript | 17 Useful Methods
42:39
DoableDanny
Рет қаралды 56 М.
Пришёл к другу на ночёвку 😂
01:00
Cadrol&Fatich
Рет қаралды 11 МЛН
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 12 МЛН
Electric Flying Bird with Hanging Wire Automatic for Ceiling Parrot
00:15
How To Get Married:   #short
00:22
Jin and Hattie
Рет қаралды 20 МЛН
React router crash course
1:04:35
Chai aur Code
Рет қаралды 285 М.
3 Beginner React Mistakes That Can Ruin Your App
20:19
Web Dev Simplified
Рет қаралды 105 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 478 М.
Speed Up Your React Apps With Code Splitting
16:50
Web Dev Simplified
Рет қаралды 383 М.
Почему удалять StrictMode плохая идея?
9:30
АйТи Синяк
Рет қаралды 17 М.
The Most Important Skill You Never Learned
34:56
Web Dev Simplified
Рет қаралды 206 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Most Beginner React Developers Do This Wrong
13:47
Web Dev Simplified
Рет қаралды 233 М.
Master CSS Overflow/Text Wrapping Like A Senior Developer
20:53
Web Dev Simplified
Рет қаралды 54 М.
Пришёл к другу на ночёвку 😂
01:00
Cadrol&Fatich
Рет қаралды 11 МЛН