React Component Lifecycle - Hooks / Methods Explained

  Рет қаралды 166,266

freeCodeCamp.org

freeCodeCamp.org

Күн бұрын

Пікірлер: 115
@freecodecamp
@freecodecamp 6 жыл бұрын
Check out our React playlist for more React tutorials: kzbin.info/aero/PLWKjhJtqVAbkArDMazoARtNz1aMwNWmvC
@Gigatless
@Gigatless 4 жыл бұрын
It's great to see someone who actually used a thing so they can explain the things you would actually need in real world.
@TricoliciSerghei
@TricoliciSerghei 6 жыл бұрын
Masterpiece example of component lifecycle! Great explanation!
@fytubevw
@fytubevw 4 жыл бұрын
Super clarity. Very calm and concise style, which makes the video easy to ingest.
@waltervenditti3174
@waltervenditti3174 2 жыл бұрын
Yeah seriously. So sick of all the "wacky" programming videos filled with terrible jokes.
@harunguven8581
@harunguven8581 3 жыл бұрын
I come from The Odin Project and find this video useful! Especially for beginners. By the way how is your Odin Project adventure going? You guys must come very close to end of Javascript course. I
@byslyrten
@byslyrten 3 жыл бұрын
Yes, it looks like we are getting kind of intermediate-advanced topics right now and I am really grateful to people who contribute this great curriculum that gets me from absolute beginner level to be able to create somewhat good level web apps.
@Fooljuice
@Fooljuice 3 жыл бұрын
Good to see another Odin Project member here! We're almost at the end, let us finish strong!
@adarshtiwari7395
@adarshtiwari7395 3 жыл бұрын
Hey fellow odin warrior😃
@othmaneelkantaoui9674
@othmaneelkantaoui9674 2 жыл бұрын
i wish the odin project gave us more videos like this instead of lengthy articles
@sarvarkhalimov111
@sarvarkhalimov111 3 жыл бұрын
Amazing tutorial to grasp concepts and where/how to use lifecycle methods. Thanks for this tutorial!
@michaelhashimoto1650
@michaelhashimoto1650 Жыл бұрын
I like class components more than functional components. It feels like you have more control.
@VigneshSharma-vrs
@VigneshSharma-vrs 6 жыл бұрын
11:50 while explaining shouldComponentUpdate, if the currentProp which is this.props.ignoreProp is not same as nextProps meaning that the prop has changed, we request for render and update. I'm little confused here, cos your code does the opposite of what I'm thinking. Please clarify.
@voyageruk2002
@voyageruk2002 6 жыл бұрын
I think it should not update if the props are === rather than !==
@deepakbisht6215
@deepakbisht6215 6 жыл бұрын
bro because the props have been updated the ignoreProp button have changed the state ignoreProp and hence the prop for the counter component using Math.random() function it would not update the componet ie return false ps - if it would be a case when math.random() generates same number twice then shouldComponentUpdate would have returned true and updated the component hope you understand
@PraveenKumar-lp6il
@PraveenKumar-lp6il 3 жыл бұрын
add props as param in error component..otherwise compile time issue will happen in new version React
@illb2fast4u
@illb2fast4u 6 жыл бұрын
Dude, this is so cool. I'm only learning JavaScript now. Just finished Vanilla JS, next up React.
@clashwithcmad
@clashwithcmad 3 жыл бұрын
It's been 3 year What going on?
@martinwest7250
@martinwest7250 2 жыл бұрын
you finished vanilla js???
@Sandeep-zu7gd
@Sandeep-zu7gd Жыл бұрын
almost 5 years are you a react master senpai now?
@abhilashpoojary3812
@abhilashpoojary3812 4 жыл бұрын
Great examples with neat explanation 😍
@ristolibera1295
@ristolibera1295 3 жыл бұрын
What an excellent tutorial!
@NotTheLastOne
@NotTheLastOne 6 жыл бұрын
18:43 you dont have the variable error in your state but you referring to this variable and it seems to be working. how does it work? it seems my react is not the same with your react thought I have the latest version
@nickkarnik9688
@nickkarnik9688 4 жыл бұрын
TheLastOne thanks for pointing that out. No idea how I missed that! It works because it is treated as any other method. It isn’t called.
@danieldejager1847
@danieldejager1847 2 жыл бұрын
Excellent tutorial , its pragmatic and to the point. Thank you.
@anant1995rawat1995
@anant1995rawat1995 3 жыл бұрын
Amazing Bro!!!!!!. Best explaination ever
@leonzchang8790
@leonzchang8790 3 жыл бұрын
thanks for the awesome video. I use create-react-app to run the code ,wondering why componentDidCatch won't show parent component but showing error
@lennygith6254
@lennygith6254 3 жыл бұрын
I also did that and got similar results. If you can please update the comment when you find an error. I'll do the same too.
@DrDemolition
@DrDemolition 3 жыл бұрын
​@@lennygith6254 It's an overlay, you can press the x on top right and get the actual render.
@ANANDSHARMA-ws2xf
@ANANDSHARMA-ws2xf 4 жыл бұрын
You explained amazing ways 👍
@mohamedreejan8143
@mohamedreejan8143 4 жыл бұрын
Clear explanations,, very useful.. thanku👍
@reynaoldman9100
@reynaoldman9100 3 жыл бұрын
Thanks, this video was very helpful for me.
@m.a6141
@m.a6141 3 жыл бұрын
Perfect Tutorial
@RafaelSFTech
@RafaelSFTech 6 жыл бұрын
Is a good pratice using methods in constructor? i think is not
@jaredgiangrasso5965
@jaredgiangrasso5965 5 жыл бұрын
I think he's defining his methods in the constructor to avoid having to bind them to 'this' in the constructor. Although I'm not sure why he doesn't just use arrow functions outside of the constructor instead which should accomplish the same thing.
@jamshyek
@jamshyek 3 жыл бұрын
Nice explanation
@sulistyoardani7314
@sulistyoardani7314 4 жыл бұрын
where ignoreCase comes from? minute 09:02
@adrielamadi8585
@adrielamadi8585 3 жыл бұрын
im actually watching this now even though it was uploaded 3 years ago.. still very useful
@natashakanji3313
@natashakanji3313 4 жыл бұрын
you made my day thanks
@karangupta725
@karangupta725 4 жыл бұрын
why we want to render even if ignore prop is same as before at around 10:59?
@sagemode37
@sagemode37 4 жыл бұрын
We are not rendering if it is same. return false if the prop is same so it won't render
@BiscuitTech
@BiscuitTech 6 жыл бұрын
This was really useful, thanks!
@karangupta725
@karangupta725 4 жыл бұрын
at 13:02 why did he used parseInt , doesn't Math.random() returns integer value?
@sagemode37
@sagemode37 4 жыл бұрын
Math.random() returns random floating point value between 0 and 1 , so we can get anything , for eg: 0.67589432 . If you multiply this by 100 --> 67.589432 . And parseInt(67.589432) will return 67 .
@mfarim
@mfarim 6 жыл бұрын
Thanks. Good Explanation...
@rajbannasa7662
@rajbannasa7662 3 жыл бұрын
Thank you so much sir ❤️
@bharathsam4355
@bharathsam4355 2 жыл бұрын
Good explaination
@VictorGarcia-si8wy
@VictorGarcia-si8wy 6 жыл бұрын
You sound just like Beau Carnes lol. Thanks for the content!
@mohammedhasanshaikh4800
@mohammedhasanshaikh4800 4 жыл бұрын
Really love your content..!!
@viditsharma3929
@viditsharma3929 4 жыл бұрын
is it not better to use setState by passing it as a function and recording the previous value?
@matrixspielt
@matrixspielt 3 жыл бұрын
Yup. Otherwise, the state could have already changed. For anyone who is wondering: this.setState(function(prevState, prevProps) {}).
@anandhegde9345
@anandhegde9345 5 жыл бұрын
if getDerivedStateFromProps is used for setting the state from props why can't it be done in constructor? We have access to props in constructor as well.
@nickkarnik9688
@nickkarnik9688 4 жыл бұрын
Anand Hegde that will work only during object creation. If props were to change after that then the getDerivedStateFromProps hook is useful.
@CarlWicker
@CarlWicker 5 жыл бұрын
Great video
@oskarolortegui9623
@oskarolortegui9623 4 жыл бұрын
So cool, please help me with this. why do you use the methods without using the ".bind(this)" into the constructor? what's the difference between doing in that way from the other way?????
@artembelyshev9467
@artembelyshev9467 4 жыл бұрын
You can use both methods depends of your situation. Using of arrow functions with ES6 is equivalent of binding to constructor
@somasundaramb2281
@somasundaramb2281 3 жыл бұрын
Hi, I have a doubt on ShouldComponentUpdate method implementation. That is, if present value and future value are different , then it should re-render.right? But,here it is not re-render Can any guide me
@adrielamadi8585
@adrielamadi8585 3 жыл бұрын
exactly, it should only re-render or set to true if the present value and the future value are different and not when they are same
@berkekaancetinkaya8721
@berkekaancetinkaya8721 4 жыл бұрын
Shouldn't you have used the prevState parameter while incrementing the state.count value? this way you are editing the state directly its not the best practice, also in Docs using prevState parameter is the best practice
@prathameshausekar
@prathameshausekar 2 жыл бұрын
Thanks a ton!
@dhrunit1018
@dhrunit1018 4 жыл бұрын
Thank you for this :)
@someone-on-earth
@someone-on-earth 8 ай бұрын
the functional approach with useEffect() and useState() would be easier imh
@harshavamsikalluri
@harshavamsikalluri 6 жыл бұрын
Thanks a lot!
@shaifuddin
@shaifuddin 2 жыл бұрын
Please do a Mantine hooks project
@martinharrisFTW
@martinharrisFTW 5 жыл бұрын
good stuff! thank you
@karangupta725
@karangupta725 4 жыл бұрын
is somebody even watching this old tutorial, other than me?
@adrielamadi8585
@adrielamadi8585 3 жыл бұрын
well... I'm watching it now lol
@lawrencemichael5571
@lawrencemichael5571 3 жыл бұрын
Hey yo!
@keevnx
@keevnx 5 жыл бұрын
What is the difference when I put the state inside constructor and state outside constructor, what is the difference?
@nickkarnik9688
@nickkarnik9688 4 жыл бұрын
Kevin Adam it’s the same. Within the constructor you have access to props.
@bilelrahmouni01
@bilelrahmouni01 4 жыл бұрын
are you explaining or showing off how rapid you are on the keyboard?
@azelsky
@azelsky 6 жыл бұрын
if we need to load up some data from a server, for example, we loaded articles and it contains some comments but data which we have contains the only id of comments. Based on it we need to make a request to receive comments. Do we make this request in ComponentDidUpdate? Because before I did it in componentWillReceiveProps but now it is legacy
@wilsongaturu134
@wilsongaturu134 5 жыл бұрын
Hi, did you solve this? I have the exact same situation. The comments need to be fetched separately and I am not sure which life cycle method to use.
@nickkarnik9688
@nickkarnik9688 5 жыл бұрын
Yes, you should make that request in ComponentDidLoad (If I understand what you're asking correctly).
@nickkarnik9688
@nickkarnik9688 5 жыл бұрын
Looking at the above comment from Wilson, I think I understand what you're asking. If you want to load comments later on, you will need to do it after your primary data loads (either in the callback or when the promise resolves). Otherwise, you might need some trigger such as clicking a button to show comments, which will make the call.
@wilsongaturu134
@wilsongaturu134 5 жыл бұрын
+Nick Karnick What we ended up doing is creating the action that fetches comments (we were using Redux) and then chaining it to the fetch articles action using ".then". This was done in the ComponentWillMount method. Since we also had comment replies that required the parent comment id, we had a fetch replies button to trigger that event as you suggest.
@crocodileman7790
@crocodileman7790 6 жыл бұрын
my generate see not working, how is that ?
@karangupta725
@karangupta725 4 жыл бұрын
dont know why in my code ,render gets printed twice in console?
@sagemode37
@sagemode37 4 жыл бұрын
Maybe you have out console.log('render') in render() method of App.js as well counter.js
@ast453000
@ast453000 3 жыл бұрын
too much focus on secondary LM methods, and not enough on the primary ones
@kavitasisodiya5846
@kavitasisodiya5846 3 жыл бұрын
Can anyone answer that why did he used "disable={this.state.mount}"
@ast453000
@ast453000 3 жыл бұрын
this.state.mount === true in the initial state. Look at the state in the constructor. So in the initial state disabled = {true} for that button. When mount is updated in state, disabled will also be updated.
@sivaganesh4489
@sivaganesh4489 4 жыл бұрын
Awesome
@ayushgupta6214
@ayushgupta6214 4 жыл бұрын
can i get the code??
@johndifelice7289
@johndifelice7289 Жыл бұрын
Where are the hooks?
@waqaspathan3337
@waqaspathan3337 Жыл бұрын
great video but take "hooks" out of the title, its misleading
@kingwindie
@kingwindie 6 жыл бұрын
ummmm, what type of vs code is this?
@nickkarnik9688
@nickkarnik9688 6 жыл бұрын
cruz I’m using Webstorm in this video. However, I would also recommend checking out CodeSandbox as I’ve used in my recent videos on my channel.
@JenniferStewart100
@JenniferStewart100 4 жыл бұрын
Now that react added hooks, this is obsolete.
@H3000-v7i
@H3000-v7i 3 жыл бұрын
Typical newbie comment
@spencerknight1730
@spencerknight1730 3 жыл бұрын
@@H3000-v7i lmao thats all programming videos. newbies trying to be the one with the information
@Jason06245
@Jason06245 Жыл бұрын
does anyone know why does my browser console print twice everything? like it prints "constructor" and "render" twice respectively follow this tutorial.
@davidlin7968
@davidlin7968 Жыл бұрын
might have to do with using strict mode
@someone-on-earth
@someone-on-earth 8 ай бұрын
you must've figured it out by now, but I'll post this for anyone facing this. this behavior of react happens only in development and its there to help us catch bugs ahead of time and its actually a feature and not a weird behavior, you should not opt out of this, but even then if you do then you can remove the wrapper.
@sarcasticdna
@sarcasticdna 4 жыл бұрын
❤️❤️❤️
@abdulghani786
@abdulghani786 4 жыл бұрын
Where the heck is hooks?? Misleading title 😐
@echonabin
@echonabin 4 жыл бұрын
He is not referring to functional hooks instead it's component life cycle hooks that's what it is said so don't be confuse i guess in functional hooks and this life cycle hooks!!
@vikashnirwal
@vikashnirwal 4 жыл бұрын
Thanks
@aashikothari3916
@aashikothari3916 9 ай бұрын
😊
@shashanksharmadon4295
@shashanksharmadon4295 4 жыл бұрын
Nyco.....
@zerosku96
@zerosku96 4 жыл бұрын
Here I am browsing through React content to find out why my **** doesn't re-render. XD
@letsmakethat2364
@letsmakethat2364 5 жыл бұрын
I watched the entire video and learned very little about React Hooks
@HaxGuru
@HaxGuru 5 жыл бұрын
Lifecycle Hooks has nothing to do with React Hooks.
@nehakhandelwal6237
@nehakhandelwal6237 3 жыл бұрын
Cannot understand a single thing why what is happening
@vishaljadhav-lf3km
@vishaljadhav-lf3km 6 жыл бұрын
First comment :)
@dec23
@dec23 5 жыл бұрын
Not helpful
@kinguinkng4403
@kinguinkng4403 4 жыл бұрын
U have micro for ASMR. Please stop using it for guides.
@ahmedmahfouz6339
@ahmedmahfouz6339 6 жыл бұрын
Please try vue it's more powerful
@GM-xk1nw
@GM-xk1nw 6 жыл бұрын
no, it's just differente
@ahmedmahfouz6339
@ahmedmahfouz6339 6 жыл бұрын
@@GM-xk1nw mention the difference
@Deliverant
@Deliverant 6 жыл бұрын
It's not more powerfull, it's "just" vastly easier to learn and super fun to use
@Albertmars32
@Albertmars32 6 жыл бұрын
The fact that react is industry standard tells me the opposite
@kwaku_2023
@kwaku_2023 2 жыл бұрын
@freecodecamp how do you set( this.setState({error, info) ) the error and info to state when it's not initialized in state (this.state), my conditional block is also not running after encountering error in nested component: if (this.state.error) { return Error Found!; }
Learn React #8: The React Lifecycle of a Functional Component
11:29
Anthony Sistilli
Рет қаралды 82 М.
The React Lifecycle: Simply Explained!
29:52
Cosden Solutions
Рет қаралды 14 М.
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
Protected Routes in React using React Router
15:40
freeCodeCamp.org
Рет қаралды 345 М.
React Hooks Course - All React Hooks Explained
1:26:21
PedroTech
Рет қаралды 1,1 МЛН
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 1 МЛН
React Component Lifecycle | React Tutorial for Beginners | KnowledgeHut
14:30
Data Structures and Algorithms in JavaScript - Full Course for Beginners
1:52:55
Redux and Modern Redux Toolkit with Asynchronous Operation - Full Course
7:47:45
10 React Hooks Explained // Plus Build your own from Scratch
13:15
Fireship
Рет қаралды 1,4 МЛН
What is mathematical thinking actually like?
9:44
Benjamin Keep, PhD, JD
Рет қаралды 19 М.
ReactJS Tutorial - 23 - Component Mounting Lifecycle Methods
10:37
Codevolution
Рет қаралды 387 М.
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН