Do you feel like youāre starting to master the basics of React? Thatās great! Because in this part, weāre going to take things to the next level and buildĀ a complete app.
Youāve learned how to use React and ReactDOM CDN links, and configure Babel in CodePen to create a React app quickly. However, this technique isĀ rarely used by professional developers.
Instead, they use automated tools to create a codebase containing essential tools that have already been preconfigured.Ā Some functionalities of these tools allow you to:
Manage different dependencies (libraries) used by an app.
Optimize code fetching in browsers.
Import CSS and images.
Manage different versions of JavaScript.
Make developing easier by refreshing the page when the code is modified.Ā
Also created by teams at Facebook, Create React App is a tool that will help you to do everythingĀ just mentioned. There are other tools available (Next, Gatsby, Parcel, etc.), but Create React App remains the standard, especially for new React users.
Create React App allows you to generate a skeleton code for your app. It includes someĀ preconfigured tools such as Webpack, Babel, and ESLint to guarantee the best development experience.Ā
To begin, get into the folder where you want to create your project. For example, Iāve created aĀ Ā workflowĀ Ā folder that sits on the same level as Downloads, Documents, etc., which is where I file all my code projects.
To start the project:
npx create-react-app jungle-house
What doesĀ Ā npxĀ mean in all of this?!
There's no need to go into too much detail as youāll only use it this once, butĀ Ā npxĀ is the command recommended by Create React App for setting up a project without having to install CRA globally or locally.
Itās loading... ā³āļøā³āļø
Yay! You now have your first project created with Create React App!
Now that youāve set up your project, itās time to get in there and start exploring the created files. You can getĀ to the project withĀ Ā cd jungle-houseĀ on your terminal.
From there, you can open your preferred text editor (Iām a fan of VS Code, personally š) to take a look. Whenever youāre ready, letās go through the files together in this screencast:Ā Ā
As you can see, you have three folders š :
Ā node_modulesĀ : where all the dependencies for your code are installed. This folder can quickly become pretty large.Ā
Ā publicĀ : whereĀ youāll find your Ā index.htmlĀ fileĀ and others relating to the online listing of your site.
Ā srcĀ : where the action happens. The essential content of the files that you create and modify will be here.
Now letās look at the most important files:
package.jsonĀ : located in your project root. Use this file to manage your dependencies (all of the tools you use to build your projects) and the scripts that youāll run withĀ Ā yarnĀ , etc. If you look at its contents, youāll see some dependencies that you recognize: React and React DOM.Ā
Here youāll findĀ Ā react-scriptsĀ , created by Facebook, which you can use to install Webpack, Babel, ESLint, etc. to make your life easier.Ā
InĀ Ā /publicĀ , youāll findĀ Ā index.htmlĀ .Ā It is the template for your application. There are lots of lines of code, but do you see Ā ```<div id="root"></div>```Ā ? Just like in the chapters before, this is whereĀ you anchor the React app.Ā
InĀ Ā /srcĀ , youāll findĀ Ā index.jsĀ , which weāll use to set up our React app.
Finally, inĀ Ā /srcĀ , youāll findĀ Ā App.jsĀ ,Ā which is our first React component.
I'm seeingĀ Ā dependenciesĀ andĀ Ā devDependenciesĀ , but whatās the difference between the two?Ā
dependenciesĀ Ā are the dependencies you need for code to work, both locally and in production. However, you only needĀ devDependenciesĀ in the development phase. Both are installed from your package manager (yarn), with the different options specified as follows:Ā Ā yarn addĀ forĀ Ā dependenciesĀ Ā andĀ Ā yarn add --devĀ forĀ Ā devDependenciesĀ .
There are two files that we wonāt use directly, but which itās a good idea to keep:
README.mdĀ , which you can use to generate an explanatory page if you put your code on GitHub, for example.
.gitignoreĀ , which specifies what should not be tracked with git (usually the largeĀ Ā Ā node_modulesĀ file).
When you find your project root, you can runĀ Ā yarn startĀ , which will run your app in the development mode.
Youāll end up with something like this (but most likely with a different IP address):

A tab should have opened in your browser with the URLĀ http://localhost:3000/. If not, open it yourself.Ā
And ta-da! š„³
You should see the glorious React logo spinning in your browser!
Let'sĀ modify the codebase so that it better resembles our project. There are several ways of organizing your code, and itās important to think about how to do it. Here weāre going to separate files according to type: components/style/images, etc.Ā Ā
Weāll start by creating aĀ /componentsĀ folderĀ inĀ Ā /srcĀ , where weāll put our components. Then dragĀ Ā App.jsĀ into it and change the import path inĀ Ā index.jsĀ .
Ā Now letās create theĀ Ā BannerĀ Ā from the previous chapter in a separate JavaScript file and call itĀ Ā banner.jsĀ .
function Banner() {
return <h1>Jungle House</h1>
}
export default BannerĀ Let's now now change the code inĀ Ā App.jsĀ by deleting the basic code and importingĀ the Ā BannerĀ .Ā
import Banner from './Banner'
Ā
function App() {
return <Banner />
}
Ā
export default AppThis gives us:

Congratulations! Youāve reused your code from the last chapter!
The tool we're using to import our components is Webpack:

WebpackĀ makes importing a component easy withĀ Ā importĀ .Ā This tool is essential for linking files together so that the browser can interpret them. And with Create React App,Ā you can install this with no configuration required. šĀ
You can begin this exercise using the codebase that we created together with Create React App.
Your mission is toĀ import theĀ Ā CartĀ component that you created in the last chapter into a separate file in theĀ Ā /componentsĀ folder.
Youāll find the solution to this exercise in the courseās GitHub repository on theĀ P2C1-SolutionĀ branch.
Developers use automated tools to make developing easier.Ā
Create React App (CRA) is a toolbox created by Facebook that remains the standard for setting up a React project.
Projects created using CRA will always have:Ā
AnĀ Ā index.htmlĀ file, which is the template where a React app will live.Ā
Ā package.jsonĀ , which lists dependencies and scripts.
Ā index.jsĀ in which our React app is set up and joined to the HTML.
CRA runs with the help of a package manager (in this course,Ā Ā yarnĀ ).
Webpack allows for the simple importing of files between one another.Ā
Did you enjoy creating your app with CRA?Ā Want to make things a bit more stylish? See you in the next chapter!Ā