Class Components vs Functional Components in React (Which is better? - Beginner's Guide)

  Рет қаралды 149,773

Sonny Sangha

Sonny Sangha

Күн бұрын

Пікірлер: 195
@SonnySangha
@SonnySangha 2 жыл бұрын
📬Do you want DAILY coding problems sent DIRECTLY to your Inbox? (with solutions the next day) 👉 links.papareact.com/university
@serenity-symphony
@serenity-symphony 3 жыл бұрын
Sony, you have mentored me in this career. highly appreciate you.
@shreyasp4789
@shreyasp4789 3 жыл бұрын
Functional based components is a winner. If you want to use class based components instead of going to react they can go for angular or vue
@alexkonstantinov4256
@alexkonstantinov4256 3 жыл бұрын
Agree, I have never seen a scenario where a class component can be useful after the introduction of hooks.
@munandisichali605
@munandisichali605 3 жыл бұрын
I agree but for more information there are no classes in vue lol
@lucasrodrigues9766
@lucasrodrigues9766 3 жыл бұрын
But you have to learn it since you will encounter projects that you will have to deal with that use class components
@alexkonstantinov4256
@alexkonstantinov4256 3 жыл бұрын
@@lucasrodrigues9766 man, we should know class components for sure to work with legacy projects. But please don’t use class components in new projects.
@mrcrypticx1
@mrcrypticx1 2 жыл бұрын
Agreed!
@meetshah4432
@meetshah4432 3 жыл бұрын
For almost a year now, I have never used class components. I just don't feel the need to use them anywhere. Functional components can do everything now that a class component can do. Also React's new docs will also replace all class components with functional.
@TheSoulCrisis
@TheSoulCrisis Жыл бұрын
Yeah functional components seems to be the future to me. I have a buddy who works for a private tech company and he usually does functional components now.
@Native-Coder
@Native-Coder 2 жыл бұрын
I write everything as class components. IDK why, but the component life cycle is more clear and makes more sense to me in a class than in a function.
@md.mehedihasan800
@md.mehedihasan800 3 жыл бұрын
I am from Bangladesh, one of the greatest programmers of all time. I like your projects very much.
@mikolots
@mikolots 2 жыл бұрын
Dude is one of the best dev teachers there is!
@aengtech
@aengtech 2 жыл бұрын
I had an argument on twitter. This video helps a lot. Thanks
2 жыл бұрын
An explanation if there is a difference in the re-renders between the two approaches would be nice.
@zhrgci
@zhrgci 2 жыл бұрын
Useful af, since I was following a tutorial that still used class components (while a guy on reddit said functional comp's were better)
@inspirationsemotivationtak1467
@inspirationsemotivationtak1467 2 жыл бұрын
Hey can you name the channel for class based components in react
@zhrgci
@zhrgci 2 жыл бұрын
@@inspirationsemotivationtak1467 @Almighty java
@TrainYourDragon999
@TrainYourDragon999 2 жыл бұрын
i first learned react and i am coding on class component, because i like coding on class component and it makes me easy to code maybe i have not coded in functional component before
@codekicks2171
@codekicks2171 2 жыл бұрын
Love you bro from India, You have made this topic very easy for us, Thanks a lot
@mikedelta658
@mikedelta658 Жыл бұрын
The one and ONLY Sonny! Thank you being my energy!!!
@alwyschwuetz
@alwyschwuetz Жыл бұрын
And that is how I understood functional and class component in less than 16 mins guys, of course after more than a few months of learning react
@johnjohnix
@johnjohnix 3 жыл бұрын
I still love using class, it is much easier when passing and updating state in a big scale project. function component is so dirty when working in a big project. Updating state from child is pain in the ass using function. Using class, you can just pass the state and you can update that state directly from child component without passing the state setter. "OR maybe I'm just missing something?"
@0080437
@0080437 3 жыл бұрын
if you want, you can write all your states into "const [state,setState]=useState({all_your_state})" and pass only state and setState to the child component. though I am not sure if this is a good practice.
@r_yan3531
@r_yan3531 2 жыл бұрын
Now this is how you teach anything 👍 Clearing fundamentals first and then diving into the project making The right way.
@guitarupfront9444
@guitarupfront9444 3 жыл бұрын
i used your link just to support you I love your content and appreciate you
@lancetakiguchi9756
@lancetakiguchi9756 3 жыл бұрын
Really great video. That last bit of syntax, of pulling out the props, and still having that catch all props at the ends seems really clean
@salvatorebarretta1410
@salvatorebarretta1410 2 жыл бұрын
u're so clean! i've learned a lot of information so quick thanks!
@CavanMitchell
@CavanMitchell 2 жыл бұрын
wow, got a lot of clarity from this vid
@Vikingsplayer
@Vikingsplayer 2 жыл бұрын
this is an fantastic video sir its clears some questions of class based components thanks
@isaacidibia2117
@isaacidibia2117 2 жыл бұрын
Very happy to come across this, i have been struggling to understand this, but now i do well a lot. Thanks
@RizaHariati
@RizaHariati 2 жыл бұрын
I never use class components since I first learn React last year. But a lot of more senior programmer do still use the class components so I have to learn it too. But it's to 'noisy' for me. This video confirms it. Thank you ^_^
@aryandhanawade8063
@aryandhanawade8063 2 жыл бұрын
React is anti-Islam !!!
@feliwein_cc
@feliwein_cc 3 жыл бұрын
fire content as always, could you make a shortcut vscode video? 11:55 kinda nice. hitting that 100k papa react! that seems like a pretty good christmas
@dimitritsikaridze6220
@dimitritsikaridze6220 3 жыл бұрын
ctrl D
@ebrahim-sani
@ebrahim-sani 3 жыл бұрын
Always love and enjoy your contents, thanks for everything 🙏
@DanyTLaw
@DanyTLaw 3 жыл бұрын
Thanks for the free month and great content. You are now my go to place when I eat lol
@mthoNtanzi
@mthoNtanzi Жыл бұрын
This is very helpful information. Really well put together.
@alamesawikanningkaton5028
@alamesawikanningkaton5028 3 жыл бұрын
Glad to see this video, i just learned react as well and confusing about which better between class and functional component. Thanks a lot sonny 😁
@subramanyashegade8248
@subramanyashegade8248 3 жыл бұрын
Thumbnail is 🔥🔥
@themoadel
@themoadel 2 жыл бұрын
love it man really you're an added value
@thatsalot3577
@thatsalot3577 2 жыл бұрын
I know that people prefer to use functional components but as an ex-game developer class component look much simpler to me as they're a bit similar to the monobehaviour classes from unity. edit: After working for more than a year in react, I'd prefer functional components they have better features and are easier to work with.
@jsomhorst
@jsomhorst 2 жыл бұрын
I really don't understand why people are so fond about functional components. To me, as a Java developer, classes are a way to accomplish this. Also the use of 'const' as being a variable is just pure nonsense. A const is a constant and not something that should be changed... just my 2 cts ;)
@latelatecheung
@latelatecheung 2 жыл бұрын
why leave game industry? if I have ability to be a game programmer, I do not want go to develop web
@thatsalot3577
@thatsalot3577 2 жыл бұрын
@@latelatecheung because I felt like being trapped inside unity, I never knew what's it's like to write low level code or something that runs on the web, I still love game development but I was really burnt out as I had to make models, textures, UI, animations, all the sounds, shaders and script for every game object all by myself, it soon started to feel overwhelming and my games were laggy af, Yeah I know I can make 2d games much faster (and as an Indie I should) but I prefer 3d games, I still make a few projects in unity and dots in my part-time but you know, I have bills to pay and learning javascript is an easy way to do that. I'm a lot mature programmer now, I may make games in my free time just not as a full time gamedev.
@thatsalot3577
@thatsalot3577 2 жыл бұрын
@@latelatecheung and if you're thinking I should use Unreal engine or something else, then yeah I tried and it just doesn't run that good with my 8 gigs of RAM.
@latelatecheung
@latelatecheung 2 жыл бұрын
@@thatsalot3577 I know you feel bro. hope you get good pay in web industry
@ashutoshpandey4171
@ashutoshpandey4171 3 жыл бұрын
1 million subscribers coming soon..., keep teaching sonny :)
@CodingFire
@CodingFire 3 жыл бұрын
100k Subscribers LETS GO!!! 🔥🔥🔥
@reach5593
@reach5593 2 жыл бұрын
Functional components since react hook came. It makes my life easier.
@chrisbrowning550
@chrisbrowning550 Жыл бұрын
Great video and nicely explained. Thank you !
@ajalasegun1
@ajalasegun1 3 жыл бұрын
I see no reason why one would want to use class components...
@priyojitchatterjee6164
@priyojitchatterjee6164 Жыл бұрын
to use the this object
@rumble1925
@rumble1925 Жыл бұрын
Lol hooks were a mistake. I know how react codebases looked before and after hooks. After is definitely more like a nice dish of spaghetti 😂
@mayurbahuguna8438
@mayurbahuguna8438 3 жыл бұрын
Man you are amazing 💫 love you brother...
@raivikas200
@raivikas200 3 жыл бұрын
100K is near 🔥🔥🔥🔥.
@srinivasulurao
@srinivasulurao 3 жыл бұрын
Doesn't seems like enough info has been provided here about why functional components are better than class component, it's not sufficient for cracking a react interview.
@SonnySangha
@SonnySangha 3 жыл бұрын
Someone call the interview police… 👮‍♂️
@ayasalem1745
@ayasalem1745 Жыл бұрын
Bro took glasses off and i was like wow new youtuber nice
@sanTakagi-gv4dy
@sanTakagi-gv4dy Жыл бұрын
Explain very clear, thanks.
@saitejagatadi9711
@saitejagatadi9711 2 жыл бұрын
Sonny, Could you please make a video on time management and how to avoid distractions. You are so great and master in time management.
@andyb9990
@andyb9990 3 жыл бұрын
Sonny could you do a React Testing video?
@thehomeschooldev6126
@thehomeschooldev6126 2 жыл бұрын
Thank you. Very well taught.
@mikaelmodig5131
@mikaelmodig5131 3 жыл бұрын
In the end of class era, you did not really use constructor and super. You just declared state as an object inside your class.
@osvaldogalvez4776
@osvaldogalvez4776 2 жыл бұрын
Thank you for the videos !
@14Shlomid
@14Shlomid Жыл бұрын
Thank you for this Video Sir. very clear, professional and helpful. so in 2023 can you suggest for new projects to use FC as the default preffered?
@mierLG
@mierLG 3 жыл бұрын
Thank you so much for a very detailed explanation, I fully understand the difference between the two.
@danuvian
@danuvian 2 жыл бұрын
Great video. It was explained very well.
@anonymousgerman2809
@anonymousgerman2809 2 жыл бұрын
great video man
@soumyanilpodder8435
@soumyanilpodder8435 3 жыл бұрын
Really good video! Very helpful...❣️
@The-Dev-Ninja
@The-Dev-Ninja 2 жыл бұрын
thank you!
@rohandeysarkar8443
@rohandeysarkar8443 3 жыл бұрын
Watched this channel grow from 5k to 100k. Way to go Sonny 🔥🔥
@salilchandwadkar789
@salilchandwadkar789 3 жыл бұрын
Awesome 🔥🔥🔥
@decathlonbo
@decathlonbo 2 жыл бұрын
I think one thing that always gets missed with these discussions is Custom Hooks. Most people who are coming from Class based components have trouble seeing the value of Functional Components. I think you did a good job explaining this, but the real value in my opinion is the ability to pull out ALL of the state logic and all of your side effects into their own custom hooks which can be consumed across all of your other components. Which allows your components to only focus on the UI and not have to worry about state at all. When I demonstrate this... that is usually when the lightbulb goes off for most people. Obviously this could be handled previously in class components with HOCs or some type of service based architecture & pure components... but with Hooks, it's so much easier to do it.
@JayroJunior
@JayroJunior 3 жыл бұрын
Very good content, thanks!
@trungphan2504
@trungphan2504 3 жыл бұрын
Nice video bro, thanks you so much
@jaygarricktheflash
@jaygarricktheflash 3 жыл бұрын
Wow! Been a bit since I watched your vids. Love the quality upgrades to the transitions and overall viewing experience. Job well done.
@riteshkhodiyar184
@riteshkhodiyar184 Жыл бұрын
You explain nicely. Just a suggestion while speaking drop the accent. for example I cant really understand when you say could and couldnt . both sound same .suggestion As non native english speaker .
@heratyian
@heratyian Жыл бұрын
I think both can be useful. I usually prefer class based components, especially for larger components with complex logic that track more than a few state variables.
@JayC00
@JayC00 Ай бұрын
One of the best Videos
@darshanakv4946
@darshanakv4946 Жыл бұрын
Best tutorial!
@specy_
@specy_ 2 жыл бұрын
This doesn't really explain the advantages and disadvantages of the each. I feel like if you have a component that has some complex state or has much functionality, class components are much easier to work with, and also performance, class based components are more performant than function based ones if you are doing frequent updates. Things get even more complicated once you start to memoise things and need to add dependency arrays and stuff. I have a pretty big webapp, I've used class components for the "macro" pages, as in, the ones which handle the overall state of the whole app, then I used functional components to make all the rest. In short: use functional components if you don't re render them often and have simple state Use class components if the component is big or does many rerenders
@SonnySangha
@SonnySangha 2 жыл бұрын
I disagree with your points, at a fundamental level functional components are lighter, more performant, and simpler to understand and implement than class based components. The above points you mentioned would only favour class based components if you aren’t applying them in a correct manner, this typically happens due to a lack of understanding hence defaulting to class based components. There is a reason why react defaults to functional components now and is deprecating class based lifecycle functions.
@specy_
@specy_ 2 жыл бұрын
@@SonnySangha my webapp on normal use has up to 50 rerenders a second, the speed of the class component comes from the fact that you don't need to "re run" and build all the functions that reside in the component itself but only the render method, while function components recreate everything at every render, you could use hooks like useCallback to improve this, but that means having to manage dependencies which is kind of annoying once you get to bigger components. I'm slowly moving away from class components and moving to functional components + mobx for state management. I have to point out that for the usual website or program, function components are fine for everything, Even larger ones, mine is more of a "special case"
@decathlonbo
@decathlonbo 2 жыл бұрын
​@@SonnySangha There is no inherent performance benefit of Hooks over Class based components or vice versus. Both have the same performance. The React team has stated they were going to provide some features that FCs + Hooks would benefit from, but nothing has been updated in that regard. @Specy I don't think you can say that Class Components are more performant for frequent updates, and then provide ways we mitigate that in Functional Components and then say you just don't like having to manage dependencies and such. Imo, handling dependencies and doing the shallow comparison is much easier and cleaner than having to handle that in a Class lifecycle method. Long story short, FCs vs Classes really comes down to preference at this time. Neither is more performant than the other, and frequent re-renders wouldn't be a reason for why you'd choose one over the other. It's why we memoized and dependency arrays.
@eip408
@eip408 3 жыл бұрын
precise explanation🔥
@sambitmohanty8308
@sambitmohanty8308 2 жыл бұрын
Doubt cleared Thank u
@jealousy0890
@jealousy0890 3 жыл бұрын
Sonny, would love to see something like a dropbox type clone, so users sign up with their own emails instead of google sign in and can upload and share files!
@binaprajapati7709
@binaprajapati7709 3 жыл бұрын
love from india dude 13 yr old here 😍
@rogerteku2877
@rogerteku2877 Жыл бұрын
Use effect in functional component while cycle in class components
@zafariqbal92
@zafariqbal92 2 жыл бұрын
Thank You!
@luqmanhrizal
@luqmanhrizal 3 жыл бұрын
Next project: VENMO Full Stack🔵!
@jasonchen8566
@jasonchen8566 3 жыл бұрын
Sonny is the best!
@naveenkumarkota2090
@naveenkumarkota2090 2 жыл бұрын
understood thank you!!
@rajeshwariy869
@rajeshwariy869 Жыл бұрын
Understand fully nice video make more video bro
@mounasellami199
@mounasellami199 2 жыл бұрын
Thank u about this gorgeous explanation Sonny, I have question! When we will be more deep in development we use Higher Order Component ?
@byalfoster
@byalfoster 2 жыл бұрын
video start at 2:43
@АлексейАлтаев-ш4о
@АлексейАлтаев-ш4о Жыл бұрын
Good explanation, but I still don't know in which cases developer supposed to use class instead functional components (Maybe I've lost something)
@kirakira160
@kirakira160 3 жыл бұрын
Sonny the best!💪💪💪
@DevlogBill
@DevlogBill 2 жыл бұрын
Hi Sonny, just found your channel by accident and you have excellent content. I just began learning React 5 days ago and I am picking it up quickly since it is functional. Before picking up React I was studying hard classes and found learning classes and creating new objects kind of confusing especially when it came to learning how to use this key word, I prefer React hooks any day of the week! Question? I am not in the tech industry yet. I am still fairly new to learning front end development. I was wondering from your personal experience, are most companies using React the new and modern way in a functional format or are most using React as a class-based system? After I get a good handle of React as function would you recommend I re learn React again but in the old way which was classes? Thanks Sonny!
@Andres_cali
@Andres_cali Жыл бұрын
Uuu and he doesn't answer
@DevlogBill
@DevlogBill Жыл бұрын
@@Andres_cali LOL I am pretty sure he got soooo many subscribers to attend too.
@empty_dayofthetech
@empty_dayofthetech Жыл бұрын
What program do you use to draw on the screen while recording?
@JC-rv2tq
@JC-rv2tq 2 жыл бұрын
Love this
@JustClickApprove92
@JustClickApprove92 3 жыл бұрын
I think it’s good to be aware of class based components, and understand how they work, but I can’t envisage a scope for using them over functional components. Currently in my job, I’m refactoring a react-native app written in class based components to functional components
@kaunghtethein3322
@kaunghtethein3322 3 жыл бұрын
that looks like so much work
@JustClickApprove92
@JustClickApprove92 3 жыл бұрын
@@kaunghtethein3322 yeah, it’s not fun 😭
@Saradomin65
@Saradomin65 3 жыл бұрын
Refactoring a code is one of the most tiring thing to do in a project lmao. You have to like really be careful that all other functionalities are still working.
@b33m0s77
@b33m0s77 2 жыл бұрын
I learned something new. Nice eyebrows
@SonnySangha
@SonnySangha 2 жыл бұрын
😉
@riz4691
@riz4691 3 жыл бұрын
Functional component is fun to use.
@Victor-wh9bs
@Victor-wh9bs 3 жыл бұрын
Good Work #PAPAFAM
@VinayKumar-1701-i7b
@VinayKumar-1701-i7b Ай бұрын
nice video sangha
@shinigami2669
@shinigami2669 2 жыл бұрын
I love to use functional components.
@harisamjad-pro
@harisamjad-pro 3 жыл бұрын
Thanks bhai!
@jasonruff1270
@jasonruff1270 3 жыл бұрын
functional components are simply superior 😈😈
@meer-cha4985
@meer-cha4985 3 жыл бұрын
What an absolute legend
@aryan7069_
@aryan7069_ 3 жыл бұрын
Great video
@frankhenry10x
@frankhenry10x 3 жыл бұрын
Sonny is ZTFSH still live/ open for Dec?
@isurujn
@isurujn 2 жыл бұрын
Hello, what's the tool you use to draw on screen btw? Looks cool.
@eriknilsson4994
@eriknilsson4994 Жыл бұрын
I think I found the program he's using. It's called ScreenBrush
@sergeydiachenko1429
@sergeydiachenko1429 8 ай бұрын
Great video. But Functional components is a hack inside React. The React team created this logic inside React for Class components added tons of boilerplate code. After years of using Class components, they are told for developers: "You need to use functional components". RIdiculous team. React is a mistake.
@なんでやねん-s8g
@なんでやねん-s8g 3 жыл бұрын
Both are better because you didn’t use open mouth photo for the thumbnail.
@ikamy
@ikamy 2 жыл бұрын
That was helpful
@arthurweasley5857
@arthurweasley5857 3 жыл бұрын
its almost 2022, why would you still use class components? well sometimes you need to but thats just an expection
@faikyesilyaprak8761
@faikyesilyaprak8761 2 жыл бұрын
Clean and pure information. Quite rare in 2021. Thanks for the great effort. Keep it up!!
@zongyu100
@zongyu100 3 жыл бұрын
Hey guys anyone knows which brand is his headset? it looks really nice
@SonnySangha
@SonnySangha 3 жыл бұрын
Audiotechnika!
@yuno3364
@yuno3364 3 жыл бұрын
lol i was just wondering if someone would make a video about this. thanks
@aribiali3574
@aribiali3574 2 жыл бұрын
you are my guy
Don't use Hooks in REACT without knowing this...
20:33
Sonny Sangha
Рет қаралды 57 М.
Learn how to use Props in React in 19 minutes (for beginners)
19:12
Sonny Sangha
Рет қаралды 150 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
From Small To Giant 0%🍫 VS 100%🍫 #katebrush #shorts #gummy
00:19
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
(Segunda parte)Técnica básica para la pesca de Lubina a Spinning.
23:21
Elquelasdejacrecer
Рет қаралды 2,3 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 811 М.
STOP Using Classes In JavaScript | Prime Reacts
14:02
ThePrimeTime
Рет қаралды 250 М.
99% React Developers Fail to Answer THIS Question!
8:56
Mehul - Codedamn
Рет қаралды 102 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 262 М.
I tried 8 different Postgres ORMs
9:46
Beyond Fireship
Рет қаралды 437 М.
You might not need useEffect() ...
21:45
Academind
Рет қаралды 175 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 489 М.
Laravel vs React
9:40
Aaron Francis
Рет қаралды 64 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН