Skip to content

Latest commit

 

History

History
216 lines (170 loc) · 4.58 KB

lecture4.mdx

File metadata and controls

216 lines (170 loc) · 4.58 KB

import { Head, Appear } from "mdx-deck"; import Logo from "./assets/images/logos/rdc-icon.svg"; export { default as theme } from "./theme"; import { CodeSurfer } from "mdx-deck-code-surfer"; import ultramin from "prism-react-renderer/themes/ultramin";

Happy Thursday!

✨ Time to finally learn about React ✨


Javascript Functions

function add(a, b) { 
    return a + b
} 
const add = function(a, b) { return a + b } // Anonymous Function
const add = (a, b) => { return a + b }  // ES6 (new) Syntax

Three different ways of making a function!


One Liners

const double = (x) => { return 2*x }  // Most verbose
const double = (x) => (2*x) // No return statement needed!
const double = x => 2*x // No {} or () needed
  1. one statement functions don't need return or {}

  2. functions with one parameter don't need parenthesis


JavaScript Objects

let a = {hello: 5, world: "hello there"}
a['hello'] // == 5
a.world // == "hello there"
a.instructors = ["Ethan", "Aivant"]

A set of key-value pairs where the keys are strings and values can be anything


Functions as Object Values

let calculator = {
    double: x => 2 * x, 
    add: (x, y) => x + y 
}
calculator.double(5) // == 10
calculator.subtract = function(x, y) { return x - y }

The values of an object can also be functions!


Array.map

let numbers = [1, 2, 3, 4, 5]
let doubled = numbers.map(x => 2 * x) 
console.log(doubled) // [2, 4, 6, 8, 10]
console.log(numbers) // [1, 2, 3, 4, 5]

Array.map transforms an array of one thing into an array of another


What is React?

React is a JS Library that lets us modularize our app via reusable components


Adding it to our Website

<body>
    ...
    <script src="https://.../react.development.js" />
    <script src="https://.../react-dom.development.js" />
</body>

This adds the code for React to our project!


Demo

Best seen through a demo! Code will be available afterwards


Review


More Review


Adding it to our page!


Congratulations!

Now you can start adding React to your websites :)

On Tuesday we'll build the beginnings of Twitter using React!