React js

33
React: A Sneak Peak Jai Santhosh UI Engineer @ Flipkart @jaisanth

Transcript of React js

Page 1: React js

React: A Sneak Peak

Jai SanthoshUI Engineer @ Flipkart

@jaisanth

Page 2: React js

Meet React.

Not yet another JS framework!

Page 3: React js

Meet React.

But just a library for creating user interfaces.

Page 4: React js

Meet React.

Renders your UI and responds to events.

Page 5: React js

Meet React.

a.k.a. The “V” in M V C

Page 6: React js

Build components, not templates

Page 7: React js

Build components, not templates

Re-render, don’t mutate

Page 8: React js

Build components, not templates

Re-render, don’t mutate

Fast Virtual DOM

Page 9: React js

• Combine DOM generation and display logic.

9

Build components, not templates

Page 10: React js

• Combine DOM generation and display logic.

• Transform data into interface components.

10

Build components, not templates

Page 11: React js

• Combine DOM generation and display logic.

• Transform data into interface components.

• Data can come from anywhere.

11

Build components, not templates

Page 12: React js

12

Build components, not templates

Page 13: React js

13

Build components, not templates

Page 14: React js

JSX

Allows you to write JS & XML

Page 15: React js

JSX

Allows you to write JS & XMLTogether!

Page 16: React js

JSX

Don’t need to use it as such

Page 17: React js

JSX

React.DOM.div({}, 'Hello ' + this.props.name)

Page 18: React js

18

Re-render, don’t mutate!

• Every component has “state” and “props”.

Page 19: React js

19

Re-render, don’t mutate!

• Every component has “state” and “props”.

• Acts as an “Immutable DOM”.

Page 20: React js

20

Re-render, don’t mutate!

• Every component has “state” and “props”.

• Acts as an “Immutable DOM”.

• Re-render the whole app once the state changes.

Page 21: React js

21

Re-render, don’t mutate!

Data is guaranteedto update!

Page 22: React js

22

Re-render, don’t mutate!

Just like the 90’s Full-page refresh!!

Page 23: React js
Page 24: React js

24

Fast Virtual DOM

Virtual DOM Makes re-rendering on every change

fast.

Page 25: React js

25

Fast Virtual DOM

On every update…

• React builds a new virtual DOM subtree

Page 26: React js

26

Fast Virtual DOM

On every update…

• React builds a new virtual DOM subtree

• …diffs it with the old one

Page 27: React js

27

Fast Virtual DOM

On every update…

• React builds a new virtual DOM subtree

• …diffs it with the old one

• …computes the minimal set of DOM mutations and puts them in a queue

Page 28: React js

28

Fast Virtual DOM

On every update…

• React builds a new virtual DOM subtree

• …diffs it with the old one

• …computes the minimal set of DOM mutations and puts them in a queue

• …and batch exexutes all updates

Page 29: React js

29

Fast Virtual DOM

• Create Node: <div className="first"><span>A Span</span></div>

none to first

first to second• Replace attribute:

className=“first" by className=“second" • Replace node: <span>A Span</span> by <p>A Paragraph</p>

second to none• Remove Node:

<div className="second"><p>A Paragraph</p></div>

Page 30: React js

30

Fast Virtual DOM

Virtual DOM is simple and fast

Page 31: React js

http://reactjs.org/#reactjs on Freenode IRCreactjs on Google Groups

Page 32: React js

• http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/

• https://news.ycombinator.com/item?id=6936975

• https://news.ycombinator.com/item?id=6937921

• http://calendar.perfplanet.com/2013/diff/

Other helpful links:

Page 33: React js

Thank You!!