Let's create our first complete app with React! š As we go through the course, weāll work together to build a website for a freelance agency, Shiny. As you can see in the Figma prototype, this site has different features that youāll work on as youĀ learn the different concepts. Every project has to start somewhere, so letās begin by setting upĀ the app and learning about ESLint and Prettier!
Weāll use Create React App (CRA) to set it up.
On your terminal, get into the folder where you want to create your project. Like in the first course, weāll go into the workflow folder that sits on the same level as Downloads, Documents, etc., where I file all my code projects.
To start the project:
npx create-react-app shiny-agency
Great, isnāt it? š¤©
Now that the project base is there, it's time to decide on its architecture.
Architecture? Even in front end?!
Donāt panic! It isnāt complex patterns. Instead, the idea is to follow logical and sufficiently clear rules to know where to put the files you create and find those you need in your codebase. React lets developers choose how to structure their projects. Check out their documentation onĀ file structure.Ā
In the chapter āDiscover Create React Appā in the previous course, we organized code by grouping files together by type: each file corresponded to a component located in the Ā /componentsĀ folder. CSS files were located in the Ā /styleĀ folder, and so on.
We will organize files similarly here, except we will add a folder for pages, which will group the components to which each route returns (weāll cover routes in the next chapter š).
Start by creating aĀ Ā /componentsĀ folder and a Ā pagesĀ folder inĀ Ā srcĀ . InĀ Ā /pagesĀ , putĀ Ā App.jsĀ ,Ā and rename itĀ Ā Home.jsxĀ .
Donāt forget to update the import paths, i.e., in Ā index.jsĀ :
import Home from './pages/Home;That givesĀ you:
āāā README.md
āāā node_modules
...
āāā package.json
āāā public
...
āāā src
ā āāā index.js
ā āāā pages
ā āāā Home.jsx
āāā yarn.lock.jsx? Since when have we needed a specific file extension to code in React?!
You donāt have to use theĀ Ā .jsxĀ extension. Your React file will also work well with a Ā .jsĀ extension, but since you can use it, isnāt it better to make everything clear? Then youāll see right away when your file contains React and when it doesnāt. š
The important thing is that you can find your files quickly. There's no one-size-fits-all solution when it comes to architecture, so you need to find a structure that works for you. Since there are fewer files, a structure by type should work well here.
Thatās twice now that weāve used the same structure ā for this course and the one before. What other options are there?
There are various possible approaches. For example, when working with a complex app with lots of big features, you might group byĀ feature. You can find a brief example of this sort of structure in theĀ React documentation.
Another structure that has worked well over the past few years is creating and organizing components using atomic design principles, which makes collaboration with designers easier. However, since our app isnāt going to be very big, it seems unnecessary to use this structure. Thatās why weāre going to organize the project for this course by file type, to make it more similar to what you would do within a company.
Now that you have the architecture, let's look at some tools to write cleaner code and avoid common errors.
JavaScript is veryĀ flexibleĀ when it comes to code errors or even just formattingāthereās no strict compilation that flags your errors. Luckily, there are tools to help with writing cleaner code!Ā
Write cleaner code? Why waste time configuring tools when Iām managing perfectly well?
Well, you might be managing well working alone on a small codebase, but imagine that youāre working on a team, where each member has their own coding style (using or not using semicolons, different rules for indenting, etc.). Itās just not efficient. š
We're going to useĀ ESLint, which will flag errors in your code (style and basic coding errors that might lead to bugs), and Prettier, which will format it.
Ā

Letās start with ESLint.
If you look at yourĀ Ā package.jsonĀ , youāll see that ESLint is already one of the tools that Create React App has preconfigured. This tool will flag errors in your code, such as using a variable that has never been declared.
Letās try it out. In Ā Home/index.jsxĀ , add a line of code making a console.log of an undeclared variable just before the Ā returnĀ :
console.log(thisIsAnError)Nothing in particular comes up. However, this is an undeclared variable, so itās an error. š¤
If you havenāt yet installed the ESLint extension in your code editor (IDE), nothing will happen.
Use VS Code to install the extension, which lets you install it directly in the Extensions tab (this will vary depending on your IDE). Once your extension is installed, your code editor should highlight your error, like this:

And there's the error!
The configuration is ready. Learn more about ESLint in the screencast below.
While ESLint flags errors in your syntax, Prettier is the standard tool for formatting your code. Unlike ESLint, Prettier is not automatically installed with Create React App.
To give you an idea of what this tool can do, take a look at this GIF š:

Ā Letās dive into the config. Start by installing the library on your terminal with Ā yarn add Ā -D prettierĀ .
Ok, great ā now what? š¤
The tool is now installed, butĀ you still have to run it manually. You want Prettier to do the work without having to think about it. The simplest way of doing this is to install the Prettier Extension directly into your IDE extensions.
Go ahead and install the extension in VS Code.

Ā And then all you need to do is go to the settings in your IDE (Ā Ā CodeĀ >Ā PreferencesĀ >Ā SettingsĀ ) to activate the commandĀ Ā formatOnSaveĀ . This will now format the file every time you save. Amazing! š
You could also go to the search bar in your IDE, type in āformat,ā and activate Ā formatOnSaveĀ :

You'reĀ not done yet! You also need to activate the option that avoids indiscriminate modification of all of your files.
Type inĀ Ā require configĀ and scroll down to the setting for Prettier. Activate the setting like this:

This way, you can specify that VS Code should only format a file when a Prettier configuration is present.
So letās make one!
At your project root, create a Ā .prettierrcĀ file in which youāll be able to set certain rules (read the Prettier documentationĀ to learn more). So, for example, if you want to delete all semicolons, youāll do the following:Ā
{
"semi": false
}If you go back to your Ā Home/index.jsxĀ file, you have:

Congratulations! You have just successfully configured ESLint and Prettier with their extensions, and now you no longer have to worry about formatting your code or making inadvertent errors! š¤
Itās now time to put this all into practice!

For this extended exercise, you're going to create a website for the freelance agency Shiny.
Here are the first steps to create your project's codebase:
Set up your project with Create React App.
Rename yourĀ index.jsĀ file at the Ā /srcĀ root asĀ Ā index.jsxĀ .
Create a Ā /componentsĀ folder and a Ā /pagesĀ folder inĀ Ā /srcĀ .
Move theĀ App.jsĀ file toĀ Ā /pagesĀ , create aĀ Ā /HomeĀ folder and rename it in Ā index.jsxĀ .
Delete the files that arenāt useful to you at the moment.
Install and configure Prettier so that you get:
{
"semi":false,
"singleQuote": true,
"tabWidth": 2
}Modify the JavaScript files according to the style defined in Ā .prettierrcĀ .
Youāll find the solution for all of this on the GitHub repository for this course, on the branch P1C2-Solution.
When starting a project, itās important to give some thought to its structure.
ESLint is a tool that flags errors in your code. Combined with its extension in your code editor, it will allow you to spot your errors instantly.
Prettier is the standard formatting tool that makes it easier for teams to work together on a codebase.Ā
Did you enjoy setting up your project, organizing it, and using essential tools for working with a company? Good, because in the next chapter, youāll learn how to secure your props with PropTypes!
See you there! š