Afghanistan
Albania
Algeria
Andorra
Anguilla
Antigua & Barbuda
Argentina
Armenia
Aruba
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire
Bosnia & Herzegovina
Botswana
Brazil
British Indian Ocean Ter
Brunei
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Canada
Canary Islands
Cape Verde
Cayman Islands
Central African Republic
Chad
Channel Islands
Chile
China
Christmas Island
Cocos Island
Colombia
Comoros
Congo
Cook Islands
Costa Rica
Cote D Ivoire
Croatia
Cuba
Curacao
Cyprus
Czech Republic
Denmark
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Ter
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guinea
Guyana
Haiti
Hawaii
Honduras
Hong Kong
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Japan
Jordan
Kazakhstan
Kenya
Kiribati
Korea North
Korea South
Kuwait
Kyrgyzstan
Laos
Latvia
Lebanon
Lesotho
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mexico
Midway Islands
Moldova
Monaco
Mongolia
Montserrat
Morocco
Mozambique
Myanmar
Nambia
Nauru
Nepal
Netherland Antilles
Netherlands (Holland, Europe)
Nevis
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
Norway
Oman
Pakistan
Palau Island
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn Island
Poland
Portugal
Puerto Rico
Qatar
Republic of Montenegro
Reunion
Romania
Russia
Rwanda
Saipan
Samoa
Samoa American
San Marino
Sao Tome & Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
Solomon Islands
Somalia
South Africa
Spain
Sri Lanka
St Barthelemy
St Eustatius
St Helena
St Kitts-Nevis
St Lucia
St Maarten
St Pierre & Miquelon
St Vincent & Grenadines
Sudan
Suriname
Swaziland
Sweden
Switzerland
Syria
Tahiti
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Tokelau
Tonga
Trinidad & Tobago
Tunisia
Turkey
Turkmenistan
Turks & Caicos Is
Tuvalu
Uganda
Ukraine
United Arab Emirates
United Kingdom
United States of America
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (Brit)
Virgin Islands (USA)
Wake Island
Wallis & Futana Is
Yemen
Zaire
Zambia
Zimbabwe
Why React?
Build own ap from scratch
Need JavaScript
Framework/Library for commercial applications.
Client-side web development
Need organizational principles
Methods don't scale.
Need jQuery.
Zsolt Nagy
Learning Goals
A new language
Event handling
Facilitate developing markup
Builds on JavaScript
Build on top commerial applications
API's for outside data.
Store values in component state
Who's this for?
Follow everything start/finish
Advanced/ Intermediate
Beginners
Showcase on GitHub
Use Forums.
What to do with this?
Get hired
Some projects will gain traction.
As a freelancer
Entry is the same: build great things
As an employee
By yourself
Invest in projects that get traction
Environment
JavaScript running on server.
Can npm packages
With terminal
General editor
Documentation
Documentation
Hint: update div id from 'root'.
Renders "Hello World" to element "root"
Run it locally as an .html
Run the sample.
Have no expectations of understanding yet.
Contribute to documenation
Components
The React. object
React include
Transforms syntax. Interpreter.
Rendering components
<div>s work
HTML notes
"Well formed" <b><p></p></b>
<self-closing/>
JSX
Can change file to .jsx from .js
React .createElement()
Syntax sugar
of attributes
JSX Exercise 2
<div id='hello'> <p>Lorum, ipsum.</p> </div>
Transform:
Trailing comma,
React .createElement(...)
into equivalent React .createElement() call
"div", { ... },
id: 'hello'
React .createElement(...)
'p',
null,
'Lorem, ipsum.'
Anti-HTML JSX
class
className
htmlFor
for
Reserved key words:
React will down-translate when rendering
Rendering 2 Elements Exercise
<HelloMessage name='Bob' />
Render 2 serial elements
<React.Fragment>
Use "fragments" to avoid injecting <div>'s
</React.Fragment>,
<HelloMessage name = 'Alkazar' />
Must be enclosed.
JavaScript Classes
Extensible through inheritance
Constructor must pass to 'super' first.
Use new operator to run constructor/ instantiate
Syntax sugar for functions.
Be careful w/ floating point numbers in JS
varargin
Creates a JS array of remaining arguments
...varargin)
Components
super(props) constructor auto-generated.
<tr> <td> {this.props.name} </td> </tr>
Renders html to target element
constructor(props)
Extend #React.Component
Need a render() to return some JSX
return ( ... multiline .. )
Split the UI into pieces
Can only have 1 parent HTML element.
Use Fragments to create an empty parent element.
First-letter Capitalized
Independent
Reuseable
Isolated
<React.Fragment>
<> </>
#Function Components
Easier to construct
More popular
Less clutter. No this.
Arrow Functions
(a,b) => a + b;
var sum =
Destructuring
var name, ticker = 'Bitcoin', 'BTC'
var { name, ticker} = coin;
Pulls key:value pairs out of objects by key names.
HTML Validator
Why
trusting unpkg.com to deliver packages.
Created by FB. All-inclusive
vs. Google's Angular.
Full force of FB dev to make a great/easy environment
Have to be downloaded
Current links are "CDN" Content Delivery Network
Going to use create-react-app
How
npm start
cd my-app
git for Windows
Convienience features
Imports react from npm package.
imrd - import react dom
Available snippets
MS Code Extension: ES7 React Redux GraphQL React-Native snippets
imrc import react component
JavaScript Snippets
Resources
Flexbox Zombies
CSS Diner
Cheat sheet
html
css
JavaScrit
jQuery
Material-UI
Be a developer, hire a designer
Or Re-Use public stuff
Property Types
Need some type checking
imprt PropTypes from 'prop-types';
className.proptypes = { key:type pairs}
HTML only deals with strings
React components take string or floating points.
Use TypeScript (another JS language)
Component State
State
Class-based components?
reset w/ this.setState()
Returned from .useState( )
React "hooks"
Function-based Components?
How is it stored in
Set with this.state
Is a namespace.
const [name, ... ] = useState ('oldValue')
Specify initial value
React states are immutable. Use const.
value getter()
2 functions
value setter()
Use seperate .useState() per property
Elements
Input for ReactDOM .render( ... )
Must create a new element and pass it to DOM to update.
Immutable
What components are built out of
Encapsulated into "stateful components"
Multiple id='root' React roots allowed
Rendering Elements
Git
Github.
gitk
What is..
... the diff ..
Cloud server
Version control software
Owned by Microsoft
"staging area"
pre-commit scratchpad.
-m switch do?
forking
git clone do?
Merging
Rebasing
Redefines which branch is main
Grafts newer changes to tip.
Merge
Copy a repository to a local drive
Making a copy yours.
Host a webpage
username.github.io
Create a new repository
Total Commander
Styled Components
Documents
const Section = styled.section` blabitty css blah`;
use `
Apply styles w/i Render statements
Converting all states to component states
npm install --save styled-components
Define named class constants in .jsx file
uuid
Prop Drilling and State Elevation
On an as-needed basis.
Pass state as parameters to lower classes in heiarchy.
Store states in highest-level class.
State Imutability
'new'
newState[0] = 'new';
const newState = state;
const state = [1,2,5];
use ... operator to copy-assign
const newState = [... state];
console.log(state[0])
1
Creates a second pointer to same array
Creates a second pointer to a new copy of the array.
PythonTutor
const newSTate = state.map (x => x);
Use map operator to create new copy on bind.
Component states
Use arrow functions to avoid bindings.
Use shallow copy
Can now define states raw in component w/o constructor
arrow function
API's
Exchange Requirements
Need "play money".
Must have "sandbox mode"
Has JavaScript API
Use Gemini.
SandBase Market must be real prices
US Citizen access
Demands
Nope.
Nope.
Nope.
Using JavaScript
Exercise
Converts to JS Array (of objects)
.then(reponse => response.json())
Contains a "readable stream"
Returns a promise.
fetch( 'https:// api.coinpaprika.com/ v1/coins')
.then( coins =>{ ... }
Axios
.get()
AwaitAll
Component #LifeCycle
Lifecycle
Methods
Diagram
JSON formatter
TypeScript
Class Component
use React.Component
.render()
can use 'refs' to reference elements in the component
Can pass props down to class components
Lifecycle methods
"Smart" or "stateful"
.constructor()
.getDerivedStateFromProps()
.componentDidMount()
Functional Component
basic JavaScript functions
regular functions
No render method.
Does not have its own "refs"
Cannot use lifecycle methods.
"dumb" or "stateless"
arrow function
can accept and use props
Mainly for UI, don't need state
typically presentational only.
Props
input/parameters a component can accept.
Treat as an immutable object
Makes a component reuseable
Style Attribute
mostly for class, but depends.
for dynamically-computed styles
React appends a "px" suffix to numeric inline style props
accepts a JavaScript object with camelCased
TypeScript Props
Use "interface"
Add the interface to component.
Optional property add suffix '?'
Defines schema of what props an object can have.