Slide 1

Slide 1 text

Introduction to React Johann Romefort Engineering Evangelist at Stylight follow Johann : @romefort follow Stylight : @codetailors

Slide 2

Slide 2 text

It’s the latest hot thing

Slide 3

Slide 3 text

Who uses React?

Slide 4

Slide 4 text

Hacker News Hiring Trends September 2015

Slide 5

Slide 5 text

Fast Growing Community ngmodules.com react-components.com 1y ago: Today: 870 modules less than 100 modules 1600 modules 1259 modules

Slide 6

Slide 6 text

What is React? “A Javascript Library for building (composable) user interfaces”

Slide 7

Slide 7 text

React is not: • Another MVC framework: React is just the V in MVC. • It does not use templates: • everything is broken down into components assembled by Javascript


Slide 8

Slide 8 text

Why React? • Simple and Performant • Declarative • Virtual DOM • Everything is a component • Small: Just a library, not a framework • Unidirectional Data-flow • Isomorphic Javascript

Slide 9

Slide 9 text

Simple and Performant • No complicated API to learn • mixing markup and code seems like an heresy at first • but it simplifies a lot of things

Slide 10

Slide 10 text

What makes UI hard to build? • Human verified: Very hard to automate testing • Lots of state • by simplifying the markup, DOM manipulation and data flow, React tried to make things more predictable by reducing complexity.

Slide 11

Slide 11 text

The Virtual DOM

Slide 12

Slide 12 text

What’s a Virtual DOM anyway? • Probably the main reason you’ll love React • Mutating the DOM is the most expensive operation • Batches mutation into Virtual DOM • React maintain a virtual representation of the DOM in memory so it can only mutate the parts of the DOM that need to be updated via a Diff algorithm

Slide 13

Slide 13 text

Re-rendering • 1 - Build new Virtual DOM subtree • 2 - Diff the new virtual DOM against old one • 3 - Compute minimal set of DOM mutations • 4 - Batch execute updates

Slide 14

Slide 14 text

Everything is a component • They are • Composable • Reusable • maintainable

Slide 15

Slide 15 text

React Component Lifecycle • Mounting • componentWillMount • componentDidMount • Updating • componentWillReceiveProps • shouldComponentUpdate • componentWillUpdate • componentDidUpdate • Unmounting • componentWillUnmount

Slide 16

Slide 16 text

Unified one-way dataflow • Simpler to reason about • Events flow up, Data flows down • reactive programming is a programming paradigm oriented around data flows and the propagation of change. This means that it should be possible to express static or dynamic data flows with ease in the programming languages used, and that the underlying execution model will automatically propagate changes through the data flow. • No databinding like in AngularJS • render method is just called everytime the data changes

Slide 17

Slide 17 text

Props vs State • props and state are JS Objects • Props are immutable: Components cannot change their props but are responsible for putting together the props of their child components • State starts with default value but can be mutated most likely from a user event • State are internals to components and “private”

Slide 18

Slide 18 text

JSX

Slide 19

Slide 19 text

What’s JSX? • JSX is a JavaScript syntax extension • It’s basically XML in your JS :) • You don’t have to use it if you don’t want to

Slide 20

Slide 20 text

Isomorphic JS • Shared JavaScript that runs on both the client & server • On first load: server-rendered HTML • Then client-side JS take over. • Faster loading time :)

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Hello React app.js app.html

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

React Dev Tools

Slide 25

Slide 25 text

Thank You! All the meetups we are organising: http://meetup.com/stylight-tech-events Follow us on twitter: @codetailors