React Component Lifecycle - Hooks / Methods Explained

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 115

  • @freecodecamp
    @freecodecamp  6 років тому +4

    Check out our React playlist for more React tutorials: ua-cam.com/play/PLWKjhJtqVAbkArDMazoARtNz1aMwNWmvC.html

  • @Gigatless
    @Gigatless 4 роки тому +18

    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 років тому +28

    Masterpiece example of component lifecycle! Great explanation!

  • @fytubevw
    @fytubevw 4 роки тому +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 роки тому +11

    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 роки тому +5

      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 роки тому +7

      Good to see another Odin Project member here! We're almost at the end, let us finish strong!

    • @adarshtiwari7395
      @adarshtiwari7395 2 роки тому +2

      Hey fellow odin warrior😃

    • @othmaneelkantaoui9674
      @othmaneelkantaoui9674 2 роки тому +1

      i wish the odin project gave us more videos like this instead of lengthy articles

  • @sarvarkhalimov111
    @sarvarkhalimov111 3 роки тому +2

    Amazing tutorial to grasp concepts and where/how to use lifecycle methods. Thanks for this tutorial!

  • @ristolibera1295
    @ristolibera1295 3 роки тому +1

    What an excellent tutorial!

  • @michaelhashimoto1650
    @michaelhashimoto1650 Рік тому +1

    I like class components more than functional components. It feels like you have more control.

  • @abhilashpoojary3812
    @abhilashpoojary3812 4 роки тому +1

    Great examples with neat explanation 😍

  • @PraveenKumar-lp6il
    @PraveenKumar-lp6il 3 роки тому +8

    add props as param in error component..otherwise compile time issue will happen in new version React

  • @illb2fast4u
    @illb2fast4u 6 років тому +5

    Dude, this is so cool. I'm only learning JavaScript now. Just finished Vanilla JS, next up React.

    • @clashwithcmad
      @clashwithcmad 3 роки тому +1

      It's been 3 year What going on?

    • @martinwest7250
      @martinwest7250 2 роки тому

      you finished vanilla js???

    • @Sandeep-zu7gd
      @Sandeep-zu7gd Рік тому +1

      almost 5 years are you a react master senpai now?

  • @leonzchang8790
    @leonzchang8790 3 роки тому +5

    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 роки тому +2

      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 роки тому +1

      ​@@lennygith6254 It's an overlay, you can press the x on top right and get the actual render.

  • @anant1995rawat1995
    @anant1995rawat1995 3 роки тому

    Amazing Bro!!!!!!. Best explaination
    ever

  • @NotTheLastOne
    @NotTheLastOne 6 років тому +2

    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.

  • @jamshyek
    @jamshyek 3 роки тому

    Nice explanation

  • @reynaoldman9100
    @reynaoldman9100 3 роки тому

    Thanks, this video was very helpful for me.

  • @m.a6141
    @m.a6141 2 роки тому

    Perfect Tutorial

  • @ANANDSHARMA-ws2xf
    @ANANDSHARMA-ws2xf 4 роки тому

    You explained amazing ways 👍

  • @bharathsam4355
    @bharathsam4355 2 роки тому

    Good explaination

  • @VigneshSharma-vrs
    @VigneshSharma-vrs 6 років тому +5

    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 років тому +1

      I think it should not update if the props are === rather than !==

    • @deepakbisht6215
      @deepakbisht6215 5 років тому

      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

  • @natashakanji3313
    @natashakanji3313 4 роки тому

    you made my day thanks

  • @mohamedreejan8143
    @mohamedreejan8143 4 роки тому

    Clear explanations,, very useful.. thanku👍

  • @sulistyoardani7314
    @sulistyoardani7314 4 роки тому +1

    where ignoreCase comes from? minute 09:02

  • @mfarim
    @mfarim 6 років тому +1

    Thanks. Good Explanation...

  • @BiscuitTech
    @BiscuitTech 6 років тому

    This was really useful, thanks!

  • @rajbannasa7662
    @rajbannasa7662 3 роки тому

    Thank you so much sir ❤️

  • @RafaelSFTech
    @RafaelSFTech 6 років тому +7

    Is a good pratice using methods in constructor? i think is not

    • @jaredgiangrasso5965
      @jaredgiangrasso5965 5 років тому +4

      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.

  • @karangupta725
    @karangupta725 4 роки тому

    at 13:02 why did he used parseInt , doesn't Math.random() returns integer value?

    • @sagemode37
      @sagemode37 4 роки тому +1

      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 .

  • @mohammedhasanshaikh4800
    @mohammedhasanshaikh4800 4 роки тому

    Really love your content..!!

  • @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

  • @viditsharma3929
    @viditsharma3929 4 роки тому +1

    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 років тому +1

    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 роки тому +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 роки тому +2

      You can use both methods depends of your situation. Using of arrow functions with ES6 is equivalent of binding to constructor

  • @somasundaramb2281
    @somasundaramb2281 3 роки тому +1

    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

  • @dhrunit1018
    @dhrunit1018 4 роки тому

    Thank you for this :)

  • @prathameshausekar
    @prathameshausekar 2 роки тому

    Thanks a ton!

  • @harshavamsikalluri
    @harshavamsikalluri 6 років тому +1

    Thanks a lot!

  • @martinharrisFTW
    @martinharrisFTW 5 років тому

    good stuff! thank you

  • @VictorGarcia-si8wy
    @VictorGarcia-si8wy 6 років тому

    You sound just like Beau Carnes lol. Thanks for the content!

  • @berkekaancetinkaya8721
    @berkekaancetinkaya8721 4 роки тому +2

    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

  • @someone-on-earth
    @someone-on-earth 7 місяців тому +1

    the functional approach with useEffect() and useState() would be easier imh

  • @shaifuddin
    @shaifuddin Рік тому

    Please do a Mantine hooks project

  • @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.

  • @adrielamadi8585
    @adrielamadi8585 3 роки тому

    im actually watching this now even though it was uploaded 3 years ago.. still very useful

  • @karangupta725
    @karangupta725 4 роки тому +2

    is somebody even watching this old tutorial, other than me?

  • @bilelrahmouni01
    @bilelrahmouni01 4 роки тому +1

    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.

  • @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.

  • @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

  • @ayushgupta6214
    @ayushgupta6214 4 роки тому

    can i get the code??

  • @waqaspathan3337
    @waqaspathan3337 Рік тому +1

    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.

  • @ast453000
    @ast453000 3 роки тому +6

    too much focus on secondary LM methods, and not enough on the primary ones

  • @sivaganesh4489
    @sivaganesh4489 4 роки тому

    Awesome

  • @johndifelice7289
    @johndifelice7289 Рік тому

    Where are the hooks?

  • @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 7 місяців тому

      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.

  • @JenniferStewart100
    @JenniferStewart100 4 роки тому +1

    Now that react added hooks, this is obsolete.

    • @H3000-v7i
      @H3000-v7i 3 роки тому +2

      Typical newbie comment

    • @spencerknight1730
      @spencerknight1730 3 роки тому

      @@H3000-v7i lmao thats all programming videos. newbies trying to be the one with the information

  • @zerosku96
    @zerosku96 4 роки тому

    Here I am browsing through React content to find out why my **** doesn't re-render. XD

  • @abdulghani786
    @abdulghani786 4 роки тому +5

    Where the heck is hooks?? Misleading title 😐

    • @echonabin
      @echonabin 4 роки тому +1

      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!!

  • @aashikothari3916
    @aashikothari3916 8 місяців тому

    😊

  • @vikashnirwal
    @vikashnirwal 4 роки тому

    Thanks

  • @shashanksharmadon4295
    @shashanksharmadon4295 4 роки тому

    Nyco.....

  • @letsmakethat2364
    @letsmakethat2364 5 років тому

    I watched the entire video and learned very little about React Hooks

    • @HaxGuru
      @HaxGuru 5 років тому +3

      Lifecycle Hooks has nothing to do with React Hooks.

  • @sarcasticdna
    @sarcasticdna 4 роки тому

    ❤️❤️❤️

  • @nehakhandelwal6237
    @nehakhandelwal6237 3 роки тому +1

    Cannot understand a single thing why what is happening

  • @kinguinkng4403
    @kinguinkng4403 3 роки тому

    U have micro for ASMR. Please stop using it for guides.

  • @vishaljadhav-lf3km
    @vishaljadhav-lf3km 6 років тому

    First comment :)

  • @dec23
    @dec23 5 років тому

    Not helpful

  • @ahmedmahfouz6339
    @ahmedmahfouz6339 6 років тому

    Please try vue it's more powerful

    • @GM-xk1nw
      @GM-xk1nw 6 років тому +1

      no, it's just differente

    • @ahmedmahfouz6339
      @ahmedmahfouz6339 6 років тому

      @@GM-xk1nw mention the difference

    • @Deliverant
      @Deliverant 6 років тому +2

      It's not more powerfull, it's "just" vastly easier to learn and super fun to use

    • @Albertmars32
      @Albertmars32 6 років тому +2

      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!;
    }