diff --git a/8-react/1-scaffold-site/README.md b/8-react/1-scaffold-site/README.md index e69de29b..df82f666 100644 --- a/8-react/1-scaffold-site/README.md +++ b/8-react/1-scaffold-site/README.md @@ -0,0 +1,221 @@ +# Scaffold a React.js app: Introduction to React.js; JSX, Scaffold your site +### Introduction + +In the previous web application projects, we learned how to build fully functional applications that runs directly in the browser using static HTML, CSS, and JavaScript. In this next chapter, we'll be using React, a declarative, efficient, and flexible JavaScript library for building modern user interfaces and web applications. It is a very popular choice when building a SPA, Single Page Application. Frameworks and libraries are commonly used in modern web applications because of the ease of starting a new project. A scaffolded project normally would have configurations, toolings and dependencies already set up and installed for you. We will be taking a practical approach by builidng a project to learn React as a frontend library and will also be linking resources such as the React documentation, for further reading. Throughtout the chapter, we will introduce concepts such as JSX, components, props, state, and lifecycle. + +In this lesson, we're going to lay out the foundations to create your very own customizable single page application portfolio in React. This lesson is the first of three lessons in the React chapter where we will first scaffold the React project, install necessary tooling and libraries, one of which is TailwindCSS, a CSS utility library and build out the structure of the porfolio. + +### Prerequisites + +As this is the last chapter of the curriculum, prerequisites are all the chapters leading up to this React chapter. + +- Basic familiarity with HTML & CSS. +- Basic knowledge of JavaScript and programming. +- Basic understanding of the DOM. +### Preparations + +You need a local web server to test the web app we'll build in this lesson. If don't have one, you will need to install [Node.js](https://nodejs.org). + +- Node.js. Make sure you version of Node.js is at least 12, or the latest stable release. +- Preferred code edition or IDE +- Terminal. MacOS and Windows both have built-in terminals. If you're using a code editor like VSCode, it also has conveniently built-in terminal. +- React devtools is recommended. It is a web browser extension that helps with developing and debugging when using React. + +## Project Setup + +### Install React + +First, we're going to boostrap the React project by installing it from our Terminal. React has a handy command `create-react-app` to run whereby it will bootsrap a starter project with all the necessary dependencies installed. You can read more about Create React App [here](https://github.com/facebook/create-react-app) Open your preferred terminal and run: + +```bash +npx create-react-app portfolio + +# OR + +npm init react-app my-app + +# OR + +yarn create react-app portfolio +``` + +The first couple of keys runs and installs React and the `portfolio` is the name of your directory. It can be anything you decide to name it, but for simplicity sake let's call it `portfolio`. [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) is a package runner tool that comes with npm 5.2+ and higher. Running one of the above commands will create a directory called `portfolio` inside the current folder (usually your home directory). + + +Once the installation is done, change directory into your project folder and open the project up in your code editor. + +```bash +cd portfolio +``` +### React project structure + +Inside that directory, it will generate the initial project structure and install the transitive dependencies: + +``` +portfolio +├── 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 + └── serviceWorker.js + └── setupTests.js +``` + +The public folder contains our assets, html static files and custom client side javascript files. package.json is used by npm (Node package manager) to save all the packages needed to deploy our app, but we don't have to worry about this because CodeSandbox installs and updates this file for us. + +In our public folder, we have a standard html file called index.html. This is our point of entry file where we have our root element, which is named by convention. If you scroll down to line 30 in the body element, you will see
. This is the root element where we will be injecting our application. + +The src folder contains all our React code and houses our index.js, app.js and later on our components when we start to create them. In index.js, you will see something like this: + +```js +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; + + +ReactDOM.render( +
+ Edit src/App.js
and save to reload.
+