1.0: Packages Setup
Last updated
Last updated
Normally, when you're working as a developer, you start with a project that has already been worked on by other developers. So you would be invited to access their git, and then clone their project. Rarely, you may get to start your own react projects. That's what we'll work through first!
Create React App , is a tool created by Facebook (the creators of React), to allow you to start developing a React application FAST, without having to configure every little thing, thereby fixing one of the cons to React development. This is the tool we'll be using to create our React applications.
run npx create-react-app react-fundamentals
in the folder where you want to create your React fundamentals stuff we'll be learning in the next week +.
next cd react-fundamentals
and then open it in your VS code. If you have installed it, you can run code .
to open it in VS code.
When you open it in your VS code you should see the following structure:
Check out the different files in your new React application. This is what it will look like every time! Here's an overview of the important files and folders, and what they do:
package.json
: this file is critical in basically all JS projects, not just React projects. This contains information about the project itself, such as author, version, scripts that it can run, and perhaps most importantly versions of packages you're using in the project. This is where packages like react are recorded with their version information, so that anyone else who wants to run your app can have the same configuration you have, so that it will work!
node_modules
: this folder is where all of the packages you specified in your package.json
get installed to when you run npm install
. Generally speaking, you never want to modify anything in node_modules
as these are third party packages.
.gitignore
: this file is a list of all the things to ignore from git. Generally speaking, node_modules and files with sensitive info go in here.
public
: this folder houses the public things, so basically what is sent when our apps get deployed, since most things read from index.html
.
src
: This folder is where all of the JavaScript and CSS files you'll create will go.
index.js
: this is the file that starts off React, by grabbing the div
from index.html
, and starting our React stuff off. We generally don't touch much in index.js
.
App.js
: the main file of our React application that we'll start developing in.
App.css
: the main CSS file for our React application.
So, for the project we're developing we need to include some extra packages beyond what create react app gave us. Make your package.json
look like this:
Then run npm install
in your terminal. This will add the packages we added in, and make sure we're on the same page in terms of packages!
So, we're going to use bootstrap in this project, as you may have noticed from the dependencies we installed above! In order to complete the installation of bootstrap, we need to add something to our App.js
. At the top, we can make our imports look like this:
Notice that we took out the logo, and added in the bootstrap import!
Now, we're going to start setting up our project for our use to learn React! The first file we're going to change, is our App.js
by clearing out all the stuff that create react app starts us with.
Make your App.js
look like the following:
Then, in your terminal, making sure you're in the react-fundamentals
folder, run npm start
. You should see the word test cenetered on your screen, hooray we've made our first change!