React.js

36
React.js

Transcript of React.js

Page 1: React.js

React.js

Page 2: React.js

How the webapplications are/were created

Server side templates + jquery

Client side templates + MVC libraries

Page 3: React.js

React.js solves all these problems with Virtual DOM

Page 4: React.js

Real DOM - simplified

Page 5: React.js

Virtual DOM - simplified

Page 6: React.js

Virtual DOM

OldNew

Result on real DOM

Page 7: React.js

Hello World

Page 8: React.js

Hello World

Page 9: React.js

JSX

Optional

Recommended for faster, easier development

Noninvasive transformer

Page 10: React.js

HelloWorld transformed

Page 11: React.js

Component properties

Page 12: React.js

Component properties validation

Page 13: React.js

Changing data

Just rerender the whole application

… or at least big part of it

Page 14: React.js

Changing data

Page 15: React.js

Changing data

Page 16: React.js

Component state

Page 17: React.js

Props vs State

Props

External data

Can’t change it

State

Internal data

Can change it

Private for component

Page 18: React.js

Lifecycle callbacks

„componentWillMount”

„componentDidMount”

„componentWillReceiveProps”

„shouldComponentUpdate”

„componentWillUpdate”

„componentDidUpdate”

„componentWillUnmount”

Page 19: React.js

Events

Page 20: React.js

Form and the state

Page 21: React.js

Form state with mixin

Page 22: React.js

Performance

Always performs only DOM necessary changes

All components are rendered by default

„shouldComponentUpdate” to control whether the rendering is required

Page 23: React.js

Performance

Page 24: React.js

Performance

Page 25: React.js

Performance

Page 26: React.js

Performance

App > TodoList > TodoItem#2

Page 27: React.js

How to implement „shouldComponentUpdate”?

Page 28: React.js

Mutable data

Page 29: React.js

Immutable data

Page 30: React.js

Immutable data

Changing the data immutable way is hard

Helpers

http://facebook.github.io/react/docs/update.html

https://github.com/facebook/immutable-js

Page 31: React.js

„shouldComponentUpdate” with immutable data

Page 32: React.js

„shouldComponentUpdate” with mixin

Page 33: React.js

Server side rendering

Page 34: React.js

Debugging

Page 35: React.js

Performance profiler

Page 36: React.js

Questions