Dr. Greg Bernstein
Updated September 17th, 2021
“A JavaScript library for building user interfaces”
“Component-Based”
We’ll be using the Parcel.jsV2 bundler for development and production builds.
We will not be using Create React App
Install Parcel Locally with: npm install parcel
Unzip and run git reset --hard
use git branch
to see all the example branches
use git checkout branchName
to checkout a particular example
Starting index.html
file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="index.css" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Dr. B's React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="index.js" type="module"></script>
</body>
</html>
Starting index.js
file:
import React from "react";
import ReactDOM from "react-dom";
// What is this? HTML mixed with JavaScript
ReactDOM.render(
<h1> Hello Website Development! </h1>,
document.getElementById("root")
);
Add the following to your package.json
file and remove the "main": ...
entry:
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html --public-url ./"
},
npm start
http://localhost:1234
"start": parcel index.html -p <port_num>
npm run build
dist
sub-directoryimport statements are for JavaScript modules, i.e., code packaging
<h1>Hello ...</h1>
is a JavaScript language extension called JSX.
ReactDOM.render(...)
is a function call to get React to render something for us.document.getElementById('root')
is a regular DOM call to get the element with the id root.