Notes

Front-End History

A front-end timeline

fetch("https://example.com/api/people")
  .then((response) => response.json())
  .then((people) => {
    const html = "<ul>";
    for (let person of data.people) {
      html += `<li>${person.lastName}, ${person.firstName}</li>`;
    }
    html += "</ul>";
    document.querySelector("#people-list").innerHTML = html;
  });
function PeopleList(props) {
  return (
    <ul>
      $
      {props.people.map((person) => (
        <li>
          {person.lastName}, {person.firstName}
        </li>
      ))}
    </ul>
  );
}

const peopleListElement = document.querySelector("#people-list");
fetch("https://example.com/api/people")
  .then((response) => response.json())
  .then((people) => {
    const props = { people };
    ReactDOM.render(<PeopleList props={props} />, peopleListElement);
  });

Using tools with React

pic
pic
fluxarch
fluxarch

Choosing React


React Concepts and Features

There are many benefits to using React over just Vanilla JS.

One-flow of data


ES6 Refresher

Exporting one item per file

ES6

export default class Wallet {
  // ...
}

// sayHello will not be exported
function sayHello() {
  console.log("Hello!");
}

CommonJS (Equivalent)

class Wallet {
  // ...
}

// sayHello will not be exported
function sayHello() {
  console.log("Hello!");
}

module.exports = Wallet;

Exporting multiple items per file

ES6 (Better to export them individually like this, rather than bunching them all into an object)

export class Wallet {
  // ...
}

export function sayHello() {
  console.log("Hello!");
}

export const sayHi = () => {
  console.log("Hi!");
};

class Wallet {
  // ...
}

function sayHello() {
  console.log("Hello!");
}

const sayHi = () => {
  console.log("Hi!");
};

export { Wallet, sayHello, sayHi };

CommonJS (Equivalent)

class Wallet {
  // ...
}

function sayHello() {
  console.log("Hello!");
}

const sayHi = () => {
  console.log("Hi!");
};

module.exports = {
  Wallet,
  sayHello,
  sayHi,
};

Importing with ES6 vs CommonJS pic

ES6

import { Wallet } from "./wallet";
import * as fs from "fs";

const wallet = new Wallet();

CommonJS

let { Wallet } = require("./wallet");

const wallet = new Wallet();

let fs = require("fs");

Unnamed default imports

// exporting
export default class Wallet {
  // ...
}

// importing
import Money from "wallet.js";

const wallet = new Money();
// exporting
export class Wallet {
  // ...
}
// importing
import { Wallet } from "wallet.js";

const wallet = new Wallet();

Aliasing imports

// export
export function sayHello() {
  console.log("Hello!");
}

export const sayHi = () => {
  console.log("Hi!");
};
//import
import * as Greetings from "greetings.js";

Greetings.sayHello(); // Hello!
Greetings.sayHi(); // Hi!
import { Wallet as W1 } from "./wallet1";
import { Wallet as W2 } from "./wallet2";

const w1 = new W1();
const w2 = new W2();

Browser support for ES6 Modules