Internal workshop react-js-mruiz

23
React A JS library for building user interfaces

Transcript of Internal workshop react-js-mruiz

Page 1: Internal workshop react-js-mruiz

ReactA JS library for building user interfaces

Page 2: Internal workshop react-js-mruiz

What we will see...● Meet React

● Fundamentals

● Components + JSX

● Props, PropType and State

● React Lifecycle

● Demo

● Want more?

Page 3: Internal workshop react-js-mruiz

Introduction

Page 4: Internal workshop react-js-mruiz

1. Not jet another JS Framework

2. Just a library for creating User

Interfaces

3. Renders your UI and respond to

events

Page 5: Internal workshop react-js-mruiz

> ReactJS has no...

● Controllers

● Directives

● Templates

● Global Event listeners

● Models

> Just components!

First fundamental...

Everything is a COMPONENT

Page 6: Internal workshop react-js-mruiz

> Changes always flow

down via props, never

up

> Callbacks and

actions will flow up

Second fundamental...

Unidirectional Data Flow

Page 7: Internal workshop react-js-mruiz

1. React builds a new

virtual DOM subtree

2. Diffs it with the

old one

3. Computes the

minimal set of DOM

mutations and puts

them in a queue

4. Batch executes all

updates

Third fundamental…

Virtual DOM Makes re-rendering on

every change fast

Page 8: Internal workshop react-js-mruiz

Creating components

“We think that markup and the code that generates it are intimately tied together”

React Docs

Page 9: Internal workshop react-js-mruiz

● Every component has

state and props

● Data is handled from

parent to child

● Owner-ownee VS

Parents-Children

● It acts as an

inmutable DOM and re-

render de app once

the state changes

wait...what´s {that}?...Angular?

Component example

Page 10: Internal workshop react-js-mruiz

JSX

{}

Page 11: Internal workshop react-js-mruiz

> Why should we learn

another template

language?

JSX

Page 12: Internal workshop react-js-mruiz

JSX → Javascript Syntax

Extension that looks

similar to XML

1. JSX is faster because

it performs

optimization while

compiling code to

JavaScript

2. It is also type-safe

and most of the

errors can be caught

during compilation

JSX

Page 13: Internal workshop react-js-mruiz

> Easy right? React conversions

Page 14: Internal workshop react-js-mruiz

Props, PropTypes & State

Page 15: Internal workshop react-js-mruiz

> Used to pass parameters

from parent to childrenProps

Page 16: Internal workshop react-js-mruiz

PropTypes> Used to catch a lot of

bug by typechecking props

Page 17: Internal workshop react-js-mruiz

> When should I use

state?

Respond to user input

Server requests

The passage of time

> Calling setState({...})

re-renders the component

State

Page 18: Internal workshop react-js-mruiz

> When should I use

state?

Respond to user input

Server requests

The passage of time

> Just use props to pass

data & event handlers

down to your child

components.

Props vs State

Page 19: Internal workshop react-js-mruiz

React Lifecycle

Page 20: Internal workshop react-js-mruiz

> componentDidMount()

Make an Ajax request to

fetch some data needed

for this component

> componentWillUnmount()

Remove any listeners you

initially set up

> componentDidMount()

Set up any listeners (ie

Websockets or Firebase

listeners)

https://staminaloops.github.io/

undefinedisnotafunction/images/

react-lifecycle.jpg

Lifecycle

Page 21: Internal workshop react-js-mruiz

> Demo has:

- Webpack (Babel &

Imports)

- React Hot Loader

- Bootstrap 3

> Steps to reproduce:

- git clone

https://github.com/B

ackSpaceTech/react-

bootstrap-

boilerplate

- npm i && npm start

DEMO TIME

Page 22: Internal workshop react-js-mruiz

What more…?React Native

Flux

Redux

ES6 Internal Workshop

Page 23: Internal workshop react-js-mruiz

Thanks!

migueloop.github.io