This course has been updated! We now recommend you take the Complete Intro to React, v7 course.

Check out a free preview of the full Complete Intro to React, v2 (feat. Router v4 and Redux) course:
The "Q&A: Shared State & createClass in ES6" Lesson is part of the full, Complete Intro to React, v2 (feat. Router v4 and Redux) course featured in this preview video. Here's what you'd learn in this lesson:

Brian spends a few minutes answering audience questions about sharing state between components and using the createClass method in ES6.

Get Unlimited Access Now

Transcript from the "Q&A: Shared State & createClass in ES6" Lesson

>> Brian Holt: So I think we have one more thing to do, and then we're actually done coding our app. Our app will be complete, and then we're gonna go back and refactor and include Redux.
>> Brian Holt: So yeah, I'll finish this, I'll push a new branch, and then I'll give you a little bit of a break.

[00:00:18] And then we'll come back and do some more.
>> Speaker 2: Question.
>> Brian Holt: Sure.
>> Speaker 2: Two questions, does this pattern of passing down methods that modify state down components happen a lot in React?
>> Brian Holt: Everywhere, all the time, extremely common.
>> Speaker 2: Okay, Tom is asking, will createClass stay available even when ES6 becomes default?

>> Brian Holt: I think the answer to that question is yes, because there's code bases like Netflix where we use it everywhere, right? We use createClass, we don't use the ES6 classes at all. And so as long as people like Netflix, where we can throw around our weight a little bit.

[00:00:52] I think as long as we're around and we keep doing it, they're gonna just keep supporting it. I think they were kind of on the track to deprecate. A bunch of people were like, woah, slow down, we like this. So just leave it in there. But at the same time, the React library is getting bigger and it needs to get smaller.

[00:01:09] So there are certain things like that that they could cut out. So suffice to say, I don't see an end to it. They haven't announced an end to it. But they probably should settle on one. And if they're gonna settle on one, it's probably gonna be ES6 classes.

[00:01:22] But that's years away, probably.
>> Brian Holt: Good question. Other questions? Something that I definitely will plug about React is, whenever they release kind of bigger, quote unquote, breaking changes. I guess not quote unquote, literally breaking changes. They generally ship a code mod with it so that, I don't know if you're familiar with code mods.

[00:01:49] But basically it's a AST transformer, an abstract syntax tree transformer, that will transform your old syntax into their new syntax. So it's an automatic refactor for you. And they're generally pretty awesome about shipping those with every single release. Same thing with the React router team is they're pretty good about including code mods with all of their releases.

[00:02:14] So if something like that where createClass went away, they would ship a code mod to probably get you about 90% there. And the rest of the stuff you would just have to slowly refactor out.
>> Brian Holt: Code mods are amazing.
>> Speaker 3: Is there a specific tool you use to apply those to your code base?

>> Brian Holt: Codemod.
>> Speaker 3: Okay, there you go.
>> Brian Holt: [LAUGH] Yeah no, it's a tool from Facebook called Codemod.
>> Brian Holt: Cool.
>> Speaker 2: There is a question, but I'm not quite sure I understand it. Denarte's asking, is there a limit on passing down action to children?
>> Speaker 2: Sorry, I got it.

[00:03:06] He or she means passing down functions.
>> Brian Holt: I think the answer to that question is you need to pass down as much as makes sense, right? There's no physical limitation, there's no limit. But the simpler you can make those interfaces, the better. So that's a really vague answer, but it's kind of just do what's best for what the situation is.

>> Speaker 2: I don't think there is a limit per say.
>> Brian Holt: No, there's no limit.
>> Speaker 2: Right.
>> Brian Holt: Absolutely not, I mean, cuz it's really just an object, right? Is there a limit on how big objects can be? Yes, but it's astronomically huge, so.
>> Brian Holt: So hopefully that's a sufficiently vague answer.

>> Brian Holt: Okay, so.
>> Brian Holt: Yeah, we'll just, did I cut a branch? I did, didn't I? I did.
>> Speaker 2: Is it possible to use propTypes on stateless components?
>> Brian Holt: Yes, same methodology that you do it with a header. You declare the function, right, and then you say function .propTypes = blah.