This course has been updated! We now recommend you take the Complete Intro to React, v7 course.
Transcript from the "Modularizing the Code" Lesson
>> Brian Holt: I don't know about you, but I find interacting or writing my code inside script tags a little gross, because it is. So what we're gonna do is we're actually gonna pull this out into a separate script file right now. So you're free to just cut all of this if you want.
[00:00:22] And then we're going to create a new folder. So I'm just gonna do it here, New Folder. Call it JS.
>> Brian Holt: And then inside JS here, I'm gonna make a new file. I'm gonna call it ClientApp.js.
>> Brian Holt: It's gonna put everything in there.
>> Brian Holt: As just a quick aside, I use Sublime, so I'm gonna show people that are using Sublime just a little useful trick.
[00:00:59] Unfortunately I don't know useful tricks for any other editor. If you Shift+Command+P and you can say install package up here, right, if you have package control, which if you're using Sublime, you should really be using package control. And then you wanna install install the babel package. I already have it installed so I'll just show you what it looks like.
[00:01:45] And I believe that there is a babel package for Adam that also works just as well.
>> Brian Holt: Okay.
>> Brian Holt: And everything will still work if you don't have that, it's just that your syntax highlighting might look a little weird sometimes. Okay, so now we've put all this inside of ClientApp.js.
>> Brian Holt: And we created the JS directory, we put in ClientApp.js,
>> Brian Holt: And back here, we're going to delete all that. And where it was, we're just gonna put now another source here. src="js/ClientApp.js"
>> Brian Holt: Okay.
>> Brian Holt: So now, hopefully, if we refresh again. It still works still works, right, it still works the way we expect it to.
>> Speaker 2: Question.
>> Brian Holt: Yeah.
>> Speaker 2: Is there a reason you put the JS folder outside the public directory?
>> Brian Holt: The reason is eventually we're going to be serving things in the public directory and we're gonna be storing all of our source in the JS directory. So things in JS will not necessarily be served later.
[00:03:10] That's a good question, and another aside I'll say is that this is not necessarily a great workshop for code organization. So definitely don't take this as gospel as the way to organize all of your code. I find that I'm ultimately always dissatisfied with the way I organize code.
[00:03:25] Like as soon as I get far enough down the road, it's like I'm an idiot, right, and so I just embrace the oblivion, I guess. [LAUGH]