React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

Similar documents
React + React Native. Based on material by Danilo Filgueira

Gearing Up for Development CS130(0)

React native. State An overview. See the tutorials at

Xtern BOOTCAMP. Week 2 Day 1 May 22, 2017

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

Web Site Development with HTML/JavaScrip

welcome to BOILERCAMP HOW TO WEB DEV

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

Lesson: Web Programming(6) Omid Jafarinezhad Sharif University of Technology

Getting Started with ReactJS

JavaScript. Like PHP, JavaScript is a modern programming language that is derived from the syntax at C.

CISC 1600 Lecture 2.4 Introduction to JavaScript

Frontend Frameworks Part 2. SWE 432, Fall 2017 Design and Implementation of Software for the Web

CGS 3066: Spring 2015 JavaScript Reference

JavaScript Fundamentals_

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

Human-Computer Interaction Design

IN Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript

React.js. a crash course. Jake Zimmerman January 29th, 2016

Client Side JavaScript and AJAX

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

ANGULAR2 OVERVIEW. The Big Picture. Getting Started. Modules and Components. Declarative Template Syntax. Forms

JavaScript CS 4640 Programming Languages for Web Applications

React(.js) the Domino Way High-Performance Client for Domino. Knut Herrmann

JavaScript. What s wrong with JavaScript?

Acknowledgments. Who Should Read This Book?...xxiv How to Read This Book...xxiv What s in This Book?...xxv Have Fun!...xxvi

INTRODUCTION TO JAVASCRIPT

CIS 3308 Logon Homework

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. ReactJS

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

A Brief Introduction to a web browser's HTML. and the Document Object Model (DOM) Lecture 28

JScript Reference. Contents

Stencil: The Time for Vanilla Web Components has Arrived

widgetjs Documentation

JavaScript: Sort of a Big Deal,

CS 130(0) JavaScript Lab

Table of Contents

CS1046 Lab 4. Timing: This lab should take you 85 to 130 minutes. Objectives: By the end of this lab you should be able to:

CSC Web Programming. JavaScript Browser Objects

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Hacking with React. Get started with React, React Router, Jest, Webpack, ES6 and more with this hands-on guide. Paul Hudson.

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

AngularJS Intro Homework

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Intro to Event-Driven Programming

React. SWE 432, Fall Web Application Development

We re working full time this summer alongside 3 UCOSP (project course) students (2 from Waterloo: Mark Rada & Su Zhang, 1 from UofT: Angelo Maralit)

Interactor Tree. Edith Law & Mike Terry

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Web Development for Dinosaurs An Introduction to Modern Web Development

React Not Just Hype!

Course 20480: Programming in HTML5 with JavaScript and CSS3

JQuery and Javascript

Sample CS 142 Midterm Examination

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Web Programming/Scripting: JavaScript

Let s create a grid of pixels that you can use for creating pixel art. CSS provides table styles for grid and table layouts.

Course Details. Skills Gained. Who Can Benefit. Prerequisites. View Online URL:

Programming in HTML5 with JavaScript and CSS3

React Loadable: Code Splitting with Server Side Rendering

Chapter Two Bonus Lesson: JavaDoc

SEEM4570 System Design and Implementation. Lecture 3 Events

(try adding using css to add some space between the bottom of the art div and the reset button, this can be done using Margins)

Reading How the Web Works

Brunch Documentation. Release Brunch team

CSCU9B2 Practical 1: Introduction to HTML 5

Project 2: After Image

! The final is at 10:30 am, Sat 6/4, in this room. ! Open book, open notes. ! No electronic devices. ! No food. ! Assignment 7 due 10pm tomorrow

WPF and MVVM Study Guides

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

jquery and AJAX

C++ for Java Programmers

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

#06 RPC & REST CLIENT/SERVER COMPUTING AND WEB TECHNOLOGIES

DECOUPLING PATTERNS, SERVICES AND CREATING AN ENTERPRISE LEVEL EDITORIAL EXPERIENCE

AIM. 10 September

Introduction to Seaside

Powerful JavaScript OOP concept here and now. CoffeeScript, TypeScript, etc

Princess Nourah bint Abdulrahman University. Computer Sciences Department

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

Beginning HTML. The Nuts and Bolts of building Web pages.

AngularJS Fundamentals

CS50 Quiz Review. November 13, 2017

CNIT 129S: Securing Web Applications. Ch 12: Attacking Users: Cross-Site Scripting (XSS) Part 2

Lab 1 - Setting up the User s Profile UI

Frontend UI Training. Whats App :

Developing Apps for the BlackBerry PlayBook

DICOM Structured Reporting: Implementation Experience

Default Parameters and Shapes. Lecture 18

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

Tutorial: Using Java/JSP to Write a Web API

INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT

CS371m - Mobile Computing. Persistence - Web Based Storage CHECK OUT g/sync-adapters/index.

PIC 40A. Midterm 1 Review

Working with JavaScript

Transcription:

Document Object Model (DOM) HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag. <head> <title>hello</title> </head> The tags have a tree-like structure, where tags can have children or a parent tag. In the example below, the <body> tag is the parent of, which is the parent of <h1> and <p>. <head> <title>hello</title> </head> <body> <h1>heading</h1> <p>here is some text.</p> </body> JavaScript/React vs. CSS In CSS, we can use background-color to manipulate background color. However, in JavaScript, this would translate to background minus color. In JavaScript/React, use camel case. For example, instead of background-color, use backgroundcolor. A useful function: getelementbyid() takes in an identifier and returns an element. For example: document.getelementbyid("main") Why Use React? Lots of websites have repetitive elements. React can help avoid lots of copying and pasting of code. 1

If you want to change something, you ll have to change it in every single element. React helps avoid this. Sometimes a piece of data has dependencies (e.g. the amount of money you have left is based on the number of cookies you bought). When one piece of data changes, others should change if necessary. With React, you don t have to manually encode these changes. React avoids having to refresh a page to update the number of likes a post has after you like it. Instead, it responds automatically right when you click it. React Coding Before you begin: install React Developer Tools, which will be super helpful for debugging. First, you ll need to import libraries in the JavaScript file (index.js). import React from "react" import ReactDOM from "react-dom" HTML goes in index.html. We can ignore package.json, which just contains some dependencies. The rest of the code goes in index.js. We ll be working in the HTML file now. Next, we ll create a React element and render it. Always make sure you call render so that your element will show up! const App = () => React.createElement("h1", null, "Hi class") ReactDOM.render(<App /> document.getelementbyid("main")) Functions The way that App is declared is different from the React lab. It follows this syntax: <func name> = (args) => <func body> The standard way of declaring a function add() is like this: function add(a, b){ return a + b; 2

or we could declare it as an anonymous function: var add = function(a, b) {return a+b; // javascript goes inside braces We can add 3 and 4 using console.log(add(3, 4)). Props Any attributes we pass into App are automatically assigned to props. For example, if you pass 7 into App using <App number = "7" />, then you can access 7 inside of App using props.number inside of App. Passing in arguments: if App takes in some props, we can render it like this. function App(props) { return React.createElement("h1", null, "hey class " + props.number); ReactDOM.render(<App number="7"/>, document.getelementbyid("main")) Filtering First, we define a function that takes in an element and returns whether it should be filtered or not. // using old style declaration function filterfunc(num){ return num > 2; // OR new style declaration const filterfunc = (num) => {return num > 2; // OR super clean style const filterfunc = num => num > 2; Now we can create an array and filter it. var arr = [1,2,3] arr.filter(filterfunc) const App = () => <h1 id="someelementid">{arr></h1> //show array 3

Components Components are the heart of React. They re used to factor out common code that will be used repeatedly. They re very similar to classes in Java! Components take in two types of input: state and props, and then output the interface. Every component needs a render() function that basically tells the component what to draw. return ( // wrapping everything in return prevents errors later <h1>howdy</h1> <p>i love dogs.</p> ) Inside a component is also the state! The state holds key:value pairs that can be used elsewhere in the component. The state gets defined in a component s constructor. Note that components are not required to have a constructor. constructor(props) { super(props) this.state = { // initialize state gold: 5, silver: 7...... Event Handling Event handlers allow you to make something happen when the user does something. 4

If we want something to happen when a button is clicked, use onclick. There are two pieces to this: We ll have a function called iwasclicked that prints to the console. We specify that iwasclicked should be called when the button is clicked. // function to specify what happens on click iwasclicked = () => { console.log("i got clicked") <button onclick={iwasclicked name="mybutton"/> click me!</button> Now let s print to the console when some input is changed. iwaschanged = () => { console.log("i got changed") <input onchange={this.iwaschanged name="myinput"/> An Example http://nicolashery.github.io/example-ui-as-data/ 5