Slide 1

Slide 1 text

A JavaScript library for building user interfaces Introduction to React

Slide 2

Slide 2 text

WHOAMI? • me@ usmanbashir.com • @ ubax • usmanbashir.com Who am I? Technology Consultant & Software Developer

Slide 3

Slide 3 text

What is React?

Slide 4

Slide 4 text

One React To Rule Them All

Slide 5

Slide 5 text

ReactJS React Native React VR

Slide 6

Slide 6 text

Learn Once, Write Anywhere

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Prerequisites

Slide 9

Slide 9 text

ES6 arrow functions classes let const template literals

Slide 10

Slide 10 text

What does React brings to the table?

Slide 11

Slide 11 text

Components Virtual DOM Props & State

Slide 12

Slide 12 text

Imperative vs. Declarative

Slide 13

Slide 13 text

Example 1

Slide 14

Slide 14 text

funtion submitForm() { // … var submitButton = $(‘button-id’); if (isFormValid === false) { submitButton.prop('disabled', true) .addClass('disabled'); } else { submitButton.prop('disabled', false) .removeClass('disabled'); } // … } Imperative (the old way)

Slide 15

Slide 15 text

Declarative (the new way)

Slide 16

Slide 16 text

Example 2

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

if (userLikes()) { if (!hasBlueLike()) { removeGrayLike(); addBlueLike(); } } else { if (hasBlueLike()) { removeBlueLike(); addGrayLike(); } } Imperative (the old way)

Slide 19

Slide 19 text

Declarative (the new way) if (this.state.liked) { return (); } else { return (); }

Slide 20

Slide 20 text

UI = RENDER(state)

Slide 21

Slide 21 text

Components

Slide 22

Slide 22 text

Declarative Components

Slide 23

Slide 23 text

Slide 24

Slide 24 text

class Button extends React.Component { render() { return ; } }

Slide 25

Slide 25 text

class Button extends React.Component { render() { return ; } }

Slide 26

Slide 26 text

class Button extends React.Component { render() { return ; } }

Slide 27

Slide 27 text

Composed Components

Slide 28

Slide 28 text

Slide 29

Slide 29 text

<PlainMenu /> <Header/>

Slide 30

Slide 30 text

<PlainMenu /> <Header/>

Slide 31

Slide 31 text

Reusable Components

Slide 32

Slide 32 text

Slide 33

Slide 33 text

Slide 34

Slide 34 text

UI composed of

Slide 35

Slide 35 text

Fast Rendering With Virtual DOM

Slide 36

Slide 36 text

Before

Virtual DOM Before

After

Virtual DOM After React Virtual DOM

Slide 37

Slide 37 text

PATCH … Set

to After … Batch of DOM operations React Virtual DOM

Slide 38

Slide 38 text

Before

Real DOM Before

After

Real DOM After Browser DOM Apply

Slide 39

Slide 39 text

Data Flow Props

Slide 40

Slide 40 text

this.props

Slide 41

Slide 41 text

Slide 42

Slide 42 text

class Welcome extends React.Component { render() { return

Hello, {this.props.name}!

; } }

Slide 43

Slide 43 text

class Welcome extends React.Component { render() { return

Hello, {this.props.name}!

; } }

Slide 44

Slide 44 text

Pure Functions

Slide 45

Slide 45 text

Data Flow State

Slide 46

Slide 46 text

this.state

Slide 47

Slide 47 text

Imperative vs. Declarative After Credits

Slide 48

Slide 48 text

Declarative (the new way)

Slide 49

Slide 49 text

class SubmitButton extends React.Component { render() { const classes = `button submit ${this.props.disabled ? “disabled” : “”}`; return ; } }

Slide 50

Slide 50 text

class SubmitButton extends React.Component { render() { const classes = `button submit ${this.props.disabled ? “disabled” : “”}`; return ; } }

Slide 51

Slide 51 text

const classes = `button submit ${this.props.disabled ? “disabled” : “”}` Template literal

Slide 52

Slide 52 text

Developer Tools

Slide 53

Slide 53 text

Create React App

Slide 54

Slide 54 text

React Developer Tools

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Usman Bashir Developer Circle Lead Workshop

Slide 57

Slide 57 text

So... • Notes & Resources • Learn more • Build something • Share it with the community What's Next?

Slide 58

Slide 58 text

Thank You