JS-201-ReactFundamentals
  • Part 0: App Overview
  • Part 1: Intro to React
    • 1.0: Packages Setup
    • 1.1: Project Setup
    • 1.2: React Router Dom
  • Part 2: JavaScript Concepts
    • 2.0: ES6 Overview
    • 2.1: classes
    • 2.2: constructors
    • 2.3: extends
    • 2.4: super
    • 2.5: interpolation
    • 2.6: map
    • 2.7: filter
  • Part 3: Functional Components
    • 3.0: Functional Components Overview
    • 3.1: Calling Functional Components
    • 3.2: Single Element Rule
    • 3.3: Arrow Functions
    • 3.4: Challenge
    • 3.4: Solution
    • 3.5: Challenge 2
    • 3.5: Solution 2
  • Part 4: JSX Challenge
    • 4.1: JSX Overview
    • 4.1: Challenge Answer
    • 4.2: className
  • Part 5: Class Concepts
    • 5.1: State
    • 5.2: setState
    • 5.3: Class Components Challenge
    • 5.4: Class Components Challenge Answer
  • Part 6: Props Starter
    • 6.0: Props Overview
    • 6.1: Props Demo and Challenge 1
    • 6.2: Props Answer 2
    • 6.3: Props Passing Functions and Challenge 2
    • 6.4: Props Answer 2
    • 6.5: External Props and Mapping Components
    • 6.6: PropTypes
  • Part 7: Lifecycle Methods
    • 7.0: Lifecycle Overview
    • 7.1: Lifecycle Methods
    • 7.2: Mounting Methods
    • 7.3: Update Methods
    • 7.4: Unmount Methods
  • Part 8: Apps
    • 1.0 - Small Timer Apps
      • 1.1 - Simple Timer
      • 1.2 - Clock App
      • 1.3 - Stop Watch App
      • 1.4 - Challenge
    • 2.0 - Concept List
      • 2.1 - Concept Data
      • 2.2 - Concept App Component
      • 2.3 - Concept Component
      • 2.4 - Concept List Component
    • 3.0 - NYT
      • 3.1 - NytApp Component
      • 3.2 - Nyt Results
    • 4.0 - The Friend List App
      • 4.1 - Friend List App Component
      • 4.2 - Friend Component
    • 5.0 - Movie Search Application
      • 5.1 - Form Component
      • 5.2 - Form Results Component
      • 5.3 - Styled Components
    • 6.0 - YouTube Api
      • 6.1 - Video Component
      • 6.2 - Video Component
      • 6.3 - Video Component
    • 7.0 - Github Api Application
      • 7.1 - The Users
      • 7.2 - Github API Component
      • 7.3 - Github API Card
      • 7.4 - Github API Card Form
      • 7.5 - Github API Card List
      • 7.6 - Github API Search
      • 7.7 - Github API Challenge
    • 8.0 - Bitcoin Api Application
      • 8.1 - Bitcoin API Setup
      • 8.2 - Bitcoin API Fetch
      • 8.3 - Bitcoin API Line Chart
      • 8.4 - Bitcoin API Fetching Data
      • 8.5 - Bitcoin API Info Box
      • 8.6 - Bitcoin API Completed Code
    • 9.0 - Google Maps Api Challenge
    • 10.0 - Sound Cloud App Challenge
    • 11.0 - VR App Challenge
    • 12.0 - React Native Intro
  • Part 9: Project
  • Part 10: Notes
    • 10.1 - Resources
    • 10.2 - Troubleshooting
Powered by GitBook
On this page
  • How Do We Start React Projects?
  • Create React App
  • Understanding the Starting Structure
  • Setting Up Our Depedencies
  • Bootstrap
  • Starting Our Project
  1. Part 1: Intro to React

1.0: Packages Setup

PreviousPart 1: Intro to ReactNext1.1: Project Setup

Last updated 7 years ago

How Do We Start React Projects?

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

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.

  1. 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 +.

  2. 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:

react-fundamentals
├── README.md
├── node_modules
├── package.json
├── .gitignore
├── public
│   ├── favicon.ico
│   ├── index.html
│   └── manifest.json
└── src
    ├── App.css
    ├── App.js
    ├── App.test.js
    ├── index.css
    ├── index.js
    ├── logo.svg
    └── registerServiceWorker.js

Understanding the Starting 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.

Setting Up Our Depedencies

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:

{
  "name": "react-fundamentals",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-scripts": "1.1.5",
    "babel-polyfill": "^6.26.0",
    "bootstrap": "^4.0.0",
    "lodash": "^4.17.4",
    "react-codepen": "^0.1.0",
    "react-icons": "^2.2.7",
    "react-router-dom": "^4.2.2",
    "react-spinners": "^0.2.5",
    "reactstrap": "^5.0.0-alpha.4",
    "youtube-api-search": "0.0.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

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!

Bootstrap

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:

import React, { Component } from 'react';
import 'bootstrap/dist/css/bootstrap.css';
import './App.css';

Notice that we took out the logo, and added in the bootstrap import!

Starting Our Project

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:

import React, { Component } from 'react';
import 'bootstrap/dist/css/bootstrap.css';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        test
      </div>
    );
  }
}

export default App;

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!

here