Slide 1

Slide 1 text

React Component-based Development

Slide 2

Slide 2 text

Helielson (Hel) @hyetho @helielson Software developer @Jusbrasil

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Agenda Components What's React How to handle data - Relay - Graphql

Slide 5

Slide 5 text

Once upon a time

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Now everything has changed

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

What’s a component?

Slide 18

Slide 18 text

"Reusable API that encapsulate a bunch of different stuff" Tom Occhino

Slide 19

Slide 19 text

FeedDocumentCard

Slide 20

Slide 20 text

Component definition

Slide 21

Slide 21 text

Benefits of using components Reusable Updatable Abstract

Slide 22

Slide 22 text

When use components Rich applications

Slide 23

Slide 23 text

JS libs and frameworks Ember Angular Polymer React

Slide 24

Slide 24 text

A javascript library for building user interfaces

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Is it a template engine like handlebars.js?

Slide 28

Slide 28 text

Nooooooooooo! "To set the record straight: React components are far more powerful than Angular templates; they should be compared with Angular’s directives instead. [Directives are Angular's way of creating custom elements]." Pete Hunt quora.com/Pete-Hunt/Posts/Facebooks-React-vs-AngularJS-A-Closer-Look

Slide 29

Slide 29 text

- It's the markup - It's the javascript - It's the behavior's function It's more than a template engine

Slide 30

Slide 30 text

helloWorld.jsx import React from 'react'; class HelloMessage extends React.Component { render() { return (
Hello {this.props.name}
); } } React.render(, mountNode);

Slide 31

Slide 31 text

helloWorld.jsx
Hello John
Result

Slide 32

Slide 32 text

- State - Events - Render - And more... React Features

Slide 33

Slide 33 text

isFollowing: false State isFollowing: true

Slide 34

Slide 34 text

Events follow()}> ...

Slide 35

Slide 35 text

ReactDOMServer.render(); Server side rendering

Slide 36

Slide 36 text

And about the data?

Slide 37

Slide 37 text

Request data

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

viewerLiked: false viewerLiked: true

Slide 40

Slide 40 text

liked = checkViewerLiked(); CONTROLLER VIEW

Slide 41

Slide 41 text

APP-1 APP-2 APP-3 APP-4

Slide 42

Slide 42 text

Let's update the component

Slide 43

Slide 43 text

liked = checkViewerLiked(); profiles = whoRecommended(); CONTROLLER VIEW

Slide 44

Slide 44 text

APP-1 APP-2 APP-3 APP-4

Slide 45

Slide 45 text

Hard to maintain

Slide 46

Slide 46 text

How to solve it?

Slide 47

Slide 47 text

Relay

Slide 48

Slide 48 text

liked = checkViewerLiked(); profiles = whoRecommended(); CONTROLLER X

Slide 49

Slide 49 text

QL Query

Slide 50

Slide 50 text

import Relay from 'react-relay'; React.createContainer(RecommendButton, { fragments: { viewer: () => Relay.QL` fragment on Document { viewerLiked, } `, } }

Slide 51

Slide 51 text

Slide 52

Slide 52 text

Just update a query

Slide 53

Slide 53 text

React.createContainer(RecommendButton, { fragments: { document: () => Relay.QL` fragment on Document { viewerLiked, whoRecommended { picture } } `, } }

Slide 54

Slide 54 text

APP-1 APP-2 APP-3 APP-4

Slide 55

Slide 55 text

Relay benefits Mutations Composition Pagination Lazy load And more...

Slide 56

Slide 56 text

New approach

Slide 57

Slide 57 text

React Componentization Relay Data-wire Graphql Data API

Slide 58

Slide 58 text

Component-based development

Slide 59

Slide 59 text

How are using?

Slide 60

Slide 60 text

Development Easy to update Easy to read Easy to compose Fast delivery

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Deep dive facebook.github.io/react facebook.github.io/relay facebook.github.io/graphql bit.ly/relay-graphql-talk bit.ly/react-talk

Slide 63

Slide 63 text

That's all folks! @hyetho @helielson Questions?