Thanks for the video, really helped me a lot ! Especially the 12/12 helped me to understand why my states weren't getting updated xD 4/12 - I always try to avoid duplication in my code however, I obey the Rule of Three of "Rules of Thumb" as well. If the logic isn't too long and/or complicated, I might tend to duplicate it instead of abstracting it until the third duplication. 2/12 - not cleaning the interval causes incrementing the count by 2 on my side.
This is crazy how much you've blown up in the last month! I saw you've created nearly 400 videos in one year, getting 50-100 views per video until recently! It's really inspiring how you never gave up!
I am a self-taught frontend developer. I know many teachers who teach online, but trust me, the way you explain things is so easy to understand. To me, you are the best teacher. I can't thank you enough. If I had money, I would have definitely bought your courses. Anyways Thank you so much for giving us your valuable time, and I love you.
I definitely prefer multiple returns. Most components end up with distinct states that make breaking it down into more declarative components easier to follow. This a personal choice I adopted from React Query tutorials. if(loading){ return } if(error){ return } return If you add a key to PostBody then React will identify each of those components as unique. That will eliminate the race condition and reduce the dependencies in the useEffect Array. Loved your explanation of the setInterval. I never quite understood the problem there.
Brother you solved many of my doubts. You have no idea how helpful and important these kind of videos are for me. Keep making such videos. Full support mate!
One of the best videos on React!!!! I've been working as a dev with react for over 1 year now and there were a lot of things in this video that I did not know! Most online courses never fully explain what happens underneath the hood, so thank you!!!
I am now quite experimented with React and already knew everything you covered in the video. But I still want to say that this video is pure bomb. The amount of useful information contained in it is quite impressive and really straight to the point. I would have love to have seen it about a year ago. :)
For me, as a backend developer it’s a pure gem. Everything I should keep in mind in a one video. So easy to refresh knowledge when I had to make some UI parts.
I am a self-learning newbie in React and you sir just made learning React a lot easier! Simple, straight to the point, no unnecessary stuff. The time I saved by watching this video instead of scouring the docs is priceless. Thank you very much.
I really love how direct and precise it is with handle certain react problems. Please do more of this format of videos.I learnt a lot and I appreciate you man. Keep it up
Absolutely fantastic video. As a kinda newbie to NextJS and REACT, I was happy that I'd figured out most of these on my own, but some of them (the object item name in brackets trick) will really help get my code leaner.
You somehow have managed to address every one of my concerns or gaps I believed I had in my knowledge across all your videos on react and Javascript. Thank you 🙏
The first case actually helped me a lot! At my job I was fixing a bug and couldn't figure out why component state was behaving wierdly, tourns out it was the multiple setState (although not direct) calls in one useEffect that were the problem
quick counter point on the 8:01 topic, using a single object to store the state of all the inputs will produce a lot of objects, the garbage collector will run more times and the component will update all the inputs that depend on the `useState` which can, some times, reduce performance significantly. By using separate states your component will update way less and create less objects and use less garbage collection cicles
Because it always was. Even with better alternatives (Solid and Svelte as you've mentioned... and more), to this day so many React devs are living with a React copium
@@DEVDerrit's not copium, I just want an existing ecosystem of packages. Component libraries, styling solutions, utility components, specific solutions libraries etc. They all exist for react and not svelte nor Solid
Nice video! Regarding the conditionnal rendering I would add to be careful with using it with numbers, for example: 0 && Hello will return the p tag, as it is not a falsy value for JS.
Very (very!) good pacing and tone of voice, coupled with gritty tricks. Love this one ! Thanks for your work ! Just watched out of curiosity after finishing fullstackopen and realized I went over every one of these mistakes during the course.
I learnt all these things by trial and error while using react in my project. This is such a brilliant video that is going to help any new developer starting with react/nextjs to avoid the pitfalls. This video is jampacked with information. Such an amazing channel.
I'm a senior dev but very new to React and modern JS. This was very helpful in showing more idiomatic ways to go about things. Thanks for a great video!
I've been developing JS for 25 years, so I'm not really making the mistakes you list, but I'm only two weeks into React and this was a great crash course on its basic mechanisms. Between the lines, you managed to make it much more clear than the horrible hand-wavy official documentation which reads like it was written by people who don't know the basics of the language.
Do you like hooks overall? I'm around 15 years into JS development. But I hate functional programming with all that half/solutions. Why would anyone prefer functions over better structured, more clean classes (long awaited) syntax and OOP approach in general? 🤷♂
@@IgorYatskiv I started React development when hooks were not yet available, and I like this new functional approach much more. I very rarely have to resort to creating any classes in very special cases.
The way I see it, classes in JavaScript and TypeScript are a less-than-useful hack that don't work in any way like I'd expect. For me, the simplicity of prototypal inheritance, functions and closures are the beautiful bits of the language. That said, I think the state of the JS/TS ecosystem is really sad and avoid it whenever possible, even though I love writing JavaScript.
I gotta thank the algorithm for recommending me this video, Wesley! You solved so many things that I was curious in the past! And with Udemy having a big sales event atm I might just grab both of your CSS + JS courses!
Likewise. Video has been helpful. I have several years of experience with JS, CSS, HTML, etc, but only been using React for 6 months or so. Just learned about using Vite over CRA the other day 😅 Hopefully I can land a React job soon!
The best thing happened to me in recent times is your video popping up on my youtube homepage suggestions. So much clarity and valuable information. Subscribed and will surely recommend your channel to every React dev in my circle
This was really helpful, I recognize a few mistakes I've done and though I've worked around the errors, your explanations gave me a better understanding to why I saw errors or such. Really cool vid and most of all thanks for sharing. I've just recently gotten serious about next.js but before that I used to fetch data in a useEffect much like you said
38:34 If you leave it as is, your "setInterval" would never be canceled until you close or reload the page. If you call setInterval or setTimeout inside useEffect, always destroy that interval / timeout.
Good stuff. I appreciate the digressions into language and syntax details. So many tutorials folks just let a code example stand on its own, and well, it's all connected.
I'd been writing handleChange functions very similar to your example on the 3rd clip without fully understanding the syntax. I know the point of that clip was different but it really helped me understand what my handlers are really doing.
Incredibly dense content full of nice tricks, best practices and clear concepts explanations. It felt like learning "the right way" of coding things in modern JS. This is the first video I watch from you and it made me buy your Udemy JS course. I'll be spending the day watching it. Looking forward for a TS course :) Cheers from Belgium !
Great video. These quick reminders are very helpful! Especially because you often see multiple ways of doing the same thing but no one explains why it works.
This video sold me to buy your courses, no faffing, straight into it with clear explanations with pros and cons and solid examples, Im a senior dev, 12 years and just this taught me a lot, cant wait to start the courses tomorrow
8:18 creating form using useState({object}) and using object restructuring with [e.target.name]= e.target.value 12:39 avoiding unnecessary useState and useEffect 14:32 premitive vs non premitive value in useState 38:09 avoid memory leak due to useEffect - 1. clearInterval 2. prev = > prev +1 42:57 Abort Controller to avoid multiple fetching on one click
11/12 - If you still need to call hooks only if a certain condition is met (like on 03:24), which is often the case in practice, you can: 1) return "No id provided" if there's no id 2) copy and paste the code between the lines 6 and 11 into a separate component in which you call those hooks indiscriminately. 3) return that component instead of lines 6-11.
As a rookie reactjs developer i skipped many fundamentals and jumped straight to the code. Now i see how such concepts was important. thx for your time doing such a helpful video.
I really enjoyed the video it is fast yet clear and concise about the details. While watching I was thinking about my previous works and realizing what went wrong and now I learned a lot. Thank you!
With one video you made me want to subscribe in a matter of seconds. Your voice and the way you are explaining and presenting it is pure satisfaction. Already subscribed everywhere!
Great video! This is a really genuine video. I really like how you explain real world scenarios, and not just regular stuff. I also watched your Prisma guide, and this type of videos are really helpful. Thanks Wesley!
Using typescript would completely ban the optional props at 3:35. It seems unusual that you'd mount a component without a prop and handle that within an if statement.
Excellent video. For the stale enclosure section, you should still have the clean up function for the setTimeout even if you are using the setCount((current) => count +1) method. The interval needs to be cleaned up when the component is unmounted.
In the first section, I think it's important to point out that the setCount function call isn't really being "scheduled". What happens is the function is run top to bottom (it renders the component), and the handleClick function is loaded and attached to the button with the current value of count. When the button is clicked, count is the same for all calls of setCount. For example, if you put a loop inside the handleClick function that takes 5 minutes to complete in between two setCount calls, one button click will still result in a single increment. Promisifying and awaiting has the same effect.
Thanks for saying this. This and some of the other explanations and examples in this video are very misleading and sometimes even flat wrong. It’s crazy how many people are just admiring the effort and taking it at face value without noticing the mistakes/problems. Another obvious example is the explanation about fetching data in useEffect without addressing the asynchronous nature of the fetch api and including practically required concepts such as async/await… There are other bad examples such as the resize listener which if declared as per the example will clear all resize listeners across the whole application and etc. I can keep going, but essentially almost every single example in this video has an issue. And we wonder why junior developers make such mistakes… because they watch videos like this one which demonstrate one type of error only to replace it with another…
You are really good at teaching. There are lots of good develovers, who create useful content but you are the best among them in tutoring. Very consistent, not emotional, focused only on confusing stuff. I am amazed
Thank you so much. I love the way you teaching. I working as a junior react developer for 2 years already, but still this video helps me a lot. Great job
The video is great. You really fast tracked me into the react shenanigans. Also how did you edited the video? Are you using something automatic to cut the silent parts?. The end result is great, the video feels like is going 2x and keeps me engaged at the same time. You have my like and sub.
A bit of advice, if you don't want to get stuck with stale states when you're updating your state based on the previous state, always use callback function instead of a raw value inside your updater function. Get used to it and this will save you a lot of time.
@amir7440 to your knowledge are there other cases where not using a callback when setting state presents an issue? Or is this just limited to useEffect?
Stale state can happen anywhere, for instance, assume a situation where you have to update your state twice or more in one single handler function. In this situation you should use callback instead of a raw value, because you will not get access to the fresh state unless you use callback. Just keep in mind that we have a so called batching state updates in this particular situation where react will update all of our states in one go (in one render), so we have to enforce react to use the freshest value on each state update. As I mentioned in my first comment, when you want to update your state based on it's previous value, always use callback and you're good to go.
A really great run through of correct patterns and component lifecycles mate, As someone who is 2 years into react, and 9 months or so into ts, I found this a really nice way to confirm my existing understanding, and clear up a few points I had only somewhat understood. Thanks for this :)
and just when i say i grasped react here bytegrad comes to drop new knowledge , thank you sir again i learned css and js from you ! now i cant wait for your nextjs course i was planning to learn it in the future. you really changing my life :,)
Thank you for the insights. You clarified my doubts with this video with mistakes that I overlook those features sometimes even I work on them. Thank you for helping out to everyone sharing your knowledge in react and other tech stack.
This is such a great and informative video, but am a little confused with this little point @21:49 couldn't we derive the loading variable from the post state not being equal to null like the 5th point in the video?
Instead of defining a dedicated state for “loading” at 22:02 , could it be derived from “posts” with a ternary ? Just like the “quantity and price” example?
The 40:48 example is itself incorrect way to fetch the data if you know you'll have an id which will reset the state of the entire component. In that case you should use a key for the component and when the key will change react will rerender and your useeffect will run reset everything for the component. This is itself encouraged by react also I believe in their why you might not need useeffect blogpost
At 42:02, do we need to use useEffect here? When the parent state changes, specifically the 'id' in this case, the parent and all of its components will render again. Consequently, when the PostBody is rendered again, it will fetch with the new 'id' value right?
Thanks for the video, really helped me a lot ! Especially the 12/12 helped me to understand why my states weren't getting updated xD
4/12 - I always try to avoid duplication in my code however, I obey the Rule of Three of "Rules of Thumb" as well. If the logic isn't too long and/or complicated, I might tend to duplicate it instead of abstracting it until the third duplication.
2/12 - not cleaning the interval causes incrementing the count by 2 on my side.
Thanks, appreciate it!
This is crazy how much you've blown up in the last month! I saw you've created nearly 400 videos in one year, getting 50-100 views per video until recently! It's really inspiring how you never gave up!
I am a self-taught frontend developer. I know many teachers who teach online, but trust me, the way you explain things is so easy to understand. To me, you are the best teacher. I can't thank you enough. If I had money, I would have definitely bought your courses. Anyways Thank you so much for giving us your valuable time, and I love you.
react is a steaming pile of hot garbage.. lol..
@@nonefvnfvnjnjnjevjenjvonej3384 no cap
I definitely prefer multiple returns. Most components end up with distinct states that make breaking it down into more declarative components easier to follow. This a personal choice I adopted from React Query tutorials.
if(loading){
return
}
if(error){
return
}
return
If you add a key to PostBody then React will identify each of those components as unique. That will eliminate the race condition and reduce the dependencies in the useEffect Array. Loved your explanation of the setInterval. I never quite understood the problem there.
I do multiple returns as well because if not, one return can become into a return hell, hard to read and follow
cant we just say:
{loading ? : error ? : }
@@pete531 Yes, but that's not very readable and scalable.
I prefer that way too
@@pete531 most teams I've been on ban nested ternaries to avoid complication in logic that is already highly complex.
I am a grumpy and impatient senior dev who was soothed by your calm voice and clear explanations. Also learnt a few things. Thanks.
Brother you solved many of my doubts. You have no idea how helpful and important these kind of videos are for me. Keep making such videos. Full support mate!
Glad to hear that
@@ByteGrad Thank You Brother 🙏
One of the best videos on React!!!! I've been working as a dev with react for over 1 year now and there were a lot of things in this video that I did not know! Most online courses never fully explain what happens underneath the hood, so thank you!!!
I am now quite experimented with React and already knew everything you covered in the video. But I still want to say that this video is pure bomb. The amount of useful information contained in it is quite impressive and really straight to the point. I would have love to have seen it about a year ago. :)
Haha thanks, appreciate it
same here, I just came to see the content but it's really helpful for the beginners, at some point I was making all these mistakes
@@Endrit719 Us bro us.
For me, as a backend developer it’s a pure gem. Everything I should keep in mind in a one video. So easy to refresh knowledge when I had to make some UI parts.
yep
I am a self-learning newbie in React and you sir just made learning React a lot easier! Simple, straight to the point, no unnecessary stuff. The time I saved by watching this video instead of scouring the docs is priceless. Thank you very much.
I really love how direct and precise it is with handle certain react problems. Please do more of this format of videos.I learnt a lot and I appreciate you man. Keep it up
Absolutely fantastic video. As a kinda newbie to NextJS and REACT, I was happy that I'd figured out most of these on my own, but some of them (the object item name in brackets trick) will really help get my code leaner.
You somehow have managed to address every one of my concerns or gaps I believed I had in my knowledge across all your videos on react and Javascript. Thank you 🙏
That's awesome!
The first case actually helped me a lot! At my job I was fixing a bug and couldn't figure out why component state was behaving wierdly, tourns out it was the multiple setState (although not direct) calls in one useEffect that were the problem
quick counter point on the 8:01 topic, using a single object to store the state of all the inputs will produce a lot of objects, the garbage collector will run more times and the component will update all the inputs that depend on the `useState` which can, some times, reduce performance significantly. By using separate states your component will update way less and create less objects and use less garbage collection cicles
Man after learning Solid and Svelte, I'm starting to find React to be so convoluted.
Because it always was. Even with better alternatives (Solid and Svelte as you've mentioned... and more), to this day so many React devs are living with a React copium
It is
@@DEVDerrit's not copium, I just want an existing ecosystem of packages. Component libraries, styling solutions, utility components, specific solutions libraries etc. They all exist for react and not svelte nor Solid
@@DEVDerr They aren't living with copium, they're living with jobs.
@@Angeal98 You can always search for general, not tied to frameworks solutions. Those exist and there is quite a lot of them.
Nice video! Regarding the conditionnal rendering I would add to be careful with using it with numbers, for example: 0 && Hello will return the p tag, as it is not a falsy value for JS.
0 is falsy in js
Very (very!) good pacing and tone of voice, coupled with gritty tricks. Love this one ! Thanks for your work ! Just watched out of curiosity after finishing fullstackopen and realized I went over every one of these mistakes during the course.
One of the best videos out there! Definitely going through all of the other videos! The tone of your voice is also relaxing!!
I learnt all these things by trial and error while using react in my project. This is such a brilliant video that is going to help any new developer starting with react/nextjs to avoid the pitfalls.
This video is jampacked with information. Such an amazing channel.
I'm a senior dev but very new to React and modern JS. This was very helpful in showing more idiomatic ways to go about things. Thanks for a great video!
Thanks! Gracias
Thanks, appreciate it!
I've been developing JS for 25 years, so I'm not really making the mistakes you list, but I'm only two weeks into React and this was a great crash course on its basic mechanisms. Between the lines, you managed to make it much more clear than the horrible hand-wavy official documentation which reads like it was written by people who don't know the basics of the language.
Do you like hooks overall? I'm around 15 years into JS development. But I hate functional programming with all that half/solutions. Why would anyone prefer functions over better structured, more clean classes (long awaited) syntax and OOP approach in general? 🤷♂
@@IgorYatskiv I started React development when hooks were not yet available, and I like this new functional approach much more. I very rarely have to resort to creating any classes in very special cases.
The way I see it, classes in JavaScript and TypeScript are a less-than-useful hack that don't work in any way like I'd expect. For me, the simplicity of prototypal inheritance, functions and closures are the beautiful bits of the language. That said, I think the state of the JS/TS ecosystem is really sad and avoid it whenever possible, even though I love writing JavaScript.
Great one! Straight to the point, typical and practical life examples! Keep it up and the volume a bit up for the future videos haha
Nice touch flipping the video as you move from editor to console 😄
Very helpful vids thx
I gotta thank the algorithm for recommending me this video, Wesley! You solved so many things that I was curious in the past! And with Udemy having a big sales event atm I might just grab both of your CSS + JS courses!
Likewise. Video has been helpful. I have several years of experience with JS, CSS, HTML, etc, but only been using React for 6 months or so. Just learned about using Vite over CRA the other day 😅 Hopefully I can land a React job soon!
The best thing happened to me in recent times is your video popping up on my youtube homepage suggestions.
So much clarity and valuable information.
Subscribed and will surely recommend your channel to every React dev in my circle
This was really helpful, I recognize a few mistakes I've done and though I've worked around the errors, your explanations gave me a better understanding to why I saw errors or such. Really cool vid and most of all thanks for sharing. I've just recently gotten serious about next.js but before that I used to fetch data in a useEffect much like you said
38:34 If you leave it as is, your "setInterval" would never be canceled until you close or reload the page. If you call setInterval or setTimeout inside useEffect, always destroy that interval / timeout.
Good stuff. I appreciate the digressions into language and syntax details. So many tutorials folks just let a code example stand on its own, and well, it's all connected.
이야 강의가 너무 기가 막혀요🥰👍 궁금했던 부분을 시원하게 긁어주는 기분이네요 감사합니당
I'd been writing handleChange functions very similar to your example on the 3rd clip without fully understanding the syntax. I know the point of that clip was different but it really helped me understand what my handlers are really doing.
Incredibly dense content full of nice tricks, best practices and clear concepts explanations. It felt like learning "the right way" of coding things in modern JS. This is the first video I watch from you and it made me buy your Udemy JS course. I'll be spending the day watching it. Looking forward for a TS course :) Cheers from Belgium !
Thx for the comment. I should look for his course online. I always study javascript with Stephen Grider; thought he was the top dog.
A well presented tutorial. Concept are explained very clearly with very short but good examples to facilitate understanding. Thank you very much.
Fantastic video! First one of yours I've come across (thanks UA-cam). I'm now a subscriber
Great video. These quick reminders are very helpful! Especially because you often see multiple ways of doing the same thing but no one explains why it works.
thanks a lot, useful video. i'm not a begginer but often i don't think about to do some more cleaner if it works. you have fixed my mind
This video sold me to buy your courses, no faffing, straight into it with clear explanations with pros and cons and solid examples, Im a senior dev, 12 years and just this taught me a lot, cant wait to start the courses tomorrow
Awesome, enjoy!
This is an amazing video! You made it simple, easy to follow, and explained everything so clearly. Thank you so much!
8:18 creating form using useState({object}) and using object restructuring with [e.target.name]= e.target.value
12:39 avoiding unnecessary useState and useEffect
14:32 premitive vs non premitive value in useState
38:09 avoid memory leak due to useEffect - 1. clearInterval 2. prev = > prev +1
42:57 Abort Controller to avoid multiple fetching on one click
11/12 - If you still need to call hooks only if a certain condition is met (like on 03:24), which is often the case in practice, you can:
1) return "No id provided" if there's no id
2) copy and paste the code between the lines 6 and 11 into a separate component in which you call those hooks indiscriminately.
3) return that component instead of lines 6-11.
Amazing. I made all of these mistakes when I started with React some years ago. Hope every React beginner's can watch this.
Saw this video, loved your straight to the point style and even bought your JS course for the projects it covers. Thanks
I just got through a week of useState and useEffect, and this video helped answer a lot of questions. Keep it up man!
Not only Junior React developers but also mids, so called seniors and all kind of full-stacks who have no idea about JS. Fantastic video :)
This is 46 minutes of pure gold! Thank you!
As a rookie reactjs developer i skipped many fundamentals and jumped straight to the code. Now i see how such concepts was important. thx for your time doing such a helpful video.
I like this way of explaining. Focusing on one thing at time. Using simple examples that are easy to understand. Nice!
Great Videos! And so fast and detailtrue. Just amazing. You are the first where it was not needed to speed up the course.
as a junior dev, this video certainly helped me solve a lot of issues I had with my code, thank you!
I really enjoyed the video it is fast yet clear and concise about the details. While watching I was thinking about my previous works and realizing what went wrong and now I learned a lot. Thank you!
I watched all the other UA-camrs and their covering of these similar topics. You by far do it the best!
Great video especially the pace at what you presented. It was 👌No time wasting and just kept going.
With one video you made me want to subscribe in a matter of seconds. Your voice and the way you are explaining and presenting it is pure satisfaction. Already subscribed everywhere!
Great video! This is a really genuine video. I really like how you explain real world scenarios, and not just regular stuff. I also watched your Prisma guide, and this type of videos are really helpful. Thanks Wesley!
Im a senior angular developer preparing for a react technical interview and this video helped me a lot. Thanks for the dedication
Thanks! Great for me as a new React Developer from Angular
With this video I lerned more in an hour than what I learned in one and a half day searching. Thanks!
really, really good explanation of everything! thanks a lot for that video. would love to see more.
Using typescript would completely ban the optional props at 3:35. It seems unusual that you'd mount a component without a prop and handle that within an if statement.
I like how you go straight up to the point. Great video. +1 subscriber
Very useful👏. Especially 14:05 this section, I have been doing unnecessary hooks all my life!
thanks so much for sharing this info for free because I never saw a free course giving like this useful info. You are from the rare people man ❤
Excellent video. For the stale enclosure section, you should still have the clean up function for the setTimeout even if you are using the setCount((current) => count +1) method. The interval needs to be cleaned up when the component is unmounted.
In the first section, I think it's important to point out that the setCount function call isn't really being "scheduled".
What happens is the function is run top to bottom (it renders the component), and the handleClick function is loaded and attached to the button with the current value of count. When the button is clicked, count is the same for all calls of setCount.
For example, if you put a loop inside the handleClick function that takes 5 minutes to complete in between two setCount calls, one button click will still result in a single increment. Promisifying and awaiting has the same effect.
Thanks for saying this. This and some of the other explanations and examples in this video are very misleading and sometimes even flat wrong. It’s crazy how many people are just admiring the effort and taking it at face value without noticing the mistakes/problems. Another obvious example is the explanation about fetching data in useEffect without addressing the asynchronous nature of the fetch api and including practically required concepts such as async/await… There are other bad examples such as the resize listener which if declared as per the example will clear all resize listeners across the whole application and etc. I can keep going, but essentially almost every single example in this video has an issue. And we wonder why junior developers make such mistakes… because they watch videos like this one which demonstrate one type of error only to replace it with another…
Great tutorial! Can you please come up with a 2nd part of this video?
I finally understood the relevance of the spread ... operator with your real world example. Thanks to you
You are really good at teaching. There are lots of good develovers, who create useful content but you are the best among them in tutoring. Very consistent, not emotional, focused only on confusing stuff. I am amazed
Thank you so much. I love the way you teaching. I working as a junior react developer for 2 years already, but still this video helps me a lot. Great job
As I was watching, there was this sudden urge to like the video multiple times, even though i'd already liked before.
Learned a lot, thanks!
The video is great. You really fast tracked me into the react shenanigans. Also how did you edited the video? Are you using something automatic to cut the silent parts?. The end result is great, the video feels like is going 2x and keeps me engaged at the same time. You have my like and sub.
As a learning developer, I run across hundreds of baity videos, but this one was really useful
A bit of advice, if you don't want to get stuck with stale states when you're updating your state based on the previous state, always use callback function instead of a raw value inside your updater function. Get used to it and this will save you a lot of time.
Thanks for the tip. Can you do a code example?
@@AlexanderSuleymanovFX I think what he means is the solution found in the video at: 38:23
setCount((prev) => prev + 1)
instead of setCount(count + 1)
@amir7440 to your knowledge are there other cases where not using a callback when setting state presents an issue? Or is this just limited to useEffect?
Stale state can happen anywhere, for instance, assume a situation where you have to update your state twice or more in one single handler function. In this situation you should use callback instead of a raw value, because you will not get access to the fresh state unless you use callback. Just keep in mind that we have a so called batching state updates in this particular situation where react will update all of our states in one go (in one render), so we have to enforce react to use the freshest value on each state update. As I mentioned in my first comment, when you want to update your state based on it's previous value, always use callback and you're good to go.
@@orere1635 Thank you!
A really great run through of correct patterns and component lifecycles mate, As someone who is 2 years into react, and 9 months or so into ts, I found this a really nice way to confirm my existing understanding, and clear up a few points I had only somewhat understood. Thanks for this :)
[2/12] while cleaning Intervals is kinda ok you can also use setTimeout in that specific example. Apart of real "prev" solution ofc
Last tip is good but abort controller will not abort calls on the api side which can further stress the api server in some cases.
and just when i say i grasped react here bytegrad comes to drop new knowledge , thank you sir again i learned css and js from you ! now i cant wait for your nextjs course i was planning to learn it in the future. you really changing my life :,)
thank you, I was overusing useEffect in some cases. If possible can you make a video in detail specifically for this case
Thank you for the insights. You clarified my doubts with this video with mistakes that I overlook those features sometimes even I work on them. Thank you for helping out to everyone sharing your knowledge in react and other tech stack.
Thank you for this video. #9 really helped me out!
21:55 You could also check if the post is null or not and use that to show if it's loading or not. Helpful video btw 👍
Nice video, I'm on my first big React project and your video helps me a lot, thank you very much!
26:45 i think typescript would still give a warning in this because type Post | null has no attributes title and body. Am I right?
This is just plain and easy to follow video with a lot of great advises, thank you.
I agree! 😉
this video is a pure gold for any React developer, junior and intermediate
This is such a great and informative video, but am a little confused with this little point @21:49 couldn't we derive the loading variable from the post state not being equal to null like the 5th point in the video?
Brilliant,,, very concise video ,, keep going make full course on react js
Instead of defining a dedicated state for “loading” at 22:02 , could it be derived from “posts” with a ternary ? Just like the “quantity and price” example?
This guy is a rock star tutor!Amazing video!
Thank you so much for this awesome explanation!! Just the video I was looking for :)
The 40:48 example is itself incorrect way to fetch the data if you know you'll have an id which will reset the state of the entire component. In that case you should use a key for the component and when the key will change react will rerender and your useeffect will run reset everything for the component.
This is itself encouraged by react also I believe in their why you might not need useeffect blogpost
Yep, great point
It's always so good to get a basic understanding like this!
Great video! You really take the time to explain everything and you do it very well
it's good mistake collection!
Thanks, appreciate it!
to save cycles, your total at 14:00 could be wrapped in a useMemo(..., [quantity]). This is especially good if your calculation is intensive..
useMemo here would be bad. You are right if it was an expensive calculation, but useMemo is not free. You would be hurting performance in the case.
After I watched this video, I purchased your 2 course. I liked your style. Thank you…
This video is amazing! Kudos. It warms my heart that I am still an intern and all of this is basically muscle memory at this point.
That's amazing thank you a lot for this video!
I like that all the details are also discussed. Great video.
Fantastic video. Just bought your professional react and nextjs course
Awesome, thank you!
At 42:02, do we need to use useEffect here? When the parent state changes, specifically the 'id' in this case, the parent and all of its components will render again. Consequently, when the PostBody is rendered again, it will fetch with the new 'id' value right?