Organizing our React application
In this recipe, we will learn how to structure our project in a better way.
How to do it...
We can create React components with the default structure that create-react-app
provides, but in this recipe, I'll show you a better way to organize the project so that we are ready when for when the application grows.
- We need to create a new React app (check the last recipe if you haven't created a React app yet)
- Currently, our React application directory tree looks like this:

- We need to create
src/components
andsrc/shared
directories - After this, we need to create the
src/components/Home
directory for our component and moveHome.js
into this folder - The
App.js
file stays at thesrc/components
level - Also,
App.css
andApp.test.js
will stay atsrc/components
level - Move the
logo.svg
file tosrc/shared/images
- Our
index.js
will stay at thesrc/
level - Now your directory tree should look like this:

Note
I highly recommend that you create another directory for shared components, src/shared...