This course has been updated! We now recommend you take the Complete Intro to React, v7 course.
Transcript from the "Lifecycle Methods Documentation" Lesson
>> Brian Holt: So, we're going to go do a ajax request real quick, just to show you kind of how that works. So, go to your details.js. And up here at the top, we're going to import axios from axios. This is just an Ajax client. I'm fine if you use any other Ajax client.
[00:00:21] I just happened to like axios because I find it really easy to use. You can use fetch in here if you want to, that's fine as well. But axios is written by my friend out of Utah and go team Utah.
>> Speaker 2: There's a request to explain the component will update life cycle method again.
[00:00:41] Do you want to cover it again?
>> Brian Holt: So yeah there is one I forgot to talk about. Which I think it is compartible update. Again not one that I typically use. No, the one I'm thinking about is component will receive props. I think it's what it is.
>> Speaker 2: Okay their asking about component will update.
>> Brian Holt: All right let's go look at the docks, because there's so many of these I can't necessarily keep them straight. React life.
>> Brian Holt: Component life cycle, component mount, renderer, component div mount, okay. Component will receive props. Should component update, component will update and component did update. So, this is like the long tail.
[00:01:27] I almost never use these. In fact, I couldn't even tell you what component will update necessarily does. So yeah, component will update is invoked immediately before rendering when new props or state are being received. So if you need it, this is what it says. If you need to prepare something before you do an update the DOM, this is where one would do it.
[00:01:46] I would say this is something more like maybe something with D3. If you're integrating directly with D3, and you need to inform D3's okay. I got a new state, I got new props, here's new data to put it into your D3 charts. But this is definitely the long tail.
[00:02:03] I've never written component will update personally.
>> Brian Holt: Component did update. There's some other long tail things here. But the docs are great, I would just suggest reading the docs. If you find yourself needing more fine granular control of life cycle.
>> Brian Holt: Like I said, 95% goes into componentDidMount().
>> Brian Holt: Component will amount force update. Yeah, that's really it.
>> Speaker 2: Can you just real quick, just go over a little bit of the things for componentDidMount, the things that you like to do there?
>> Brian Holt: Yeah.
>> Speaker 2: Cuz that happens only in the browser.
>> Brian Holt: Yep, so anything you have to interact with the DOM, AJAX calls, event listeners, and integration with external libraries.
[00:02:53] That's, that's most of it.
>> Brian Holt: Okay. Check out the react docs on this, they're pretty explicit and they are really good.