21
React An introduction

React talk, GrunnJs 24 September 2014

  • Upload
    jjoos

  • View
    260

  • Download
    2

Embed Size (px)

DESCRIPTION

React has a different design than other frameworks and will influence front end Javascript frameworks for years. I'll give an overview of what sets it apart and walk through some example code to get you up and running with React.

Citation preview

Page 1: React talk, GrunnJs 24 September 2014

ReactAn introduction

Page 2: React talk, GrunnJs 24 September 2014

`whoami`

• software engineer @ HackerOne

• apprentice of all trades (hardware, vms, backend, frontend)

• works mostly in CoffeeScript

• @jjoos / [email protected]

Page 3: React talk, GrunnJs 24 September 2014

What is React?curl  https://github.com/facebook/react/blob/master/README.md

Page 4: React talk, GrunnJs 24 September 2014

Interest in React• xhp is not adopted

• released one year ago

• Facebook, Instagram, Airbnb, Khan Academy, Mozilla, Github, etc.

• New frameworks using React concepts: mithril, elm, mercury and ractive

Page 5: React talk, GrunnJs 24 September 2014

–Tyler Renelle

“I’ve seen React as the replacement for the views component of Angular.”

Page 6: React talk, GrunnJs 24 September 2014

Display logic and templates

Page 7: React talk, GrunnJs 24 September 2014

Getting started

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

Page 8: React talk, GrunnJs 24 September 2014

More advanced

Page 9: React talk, GrunnJs 24 September 2014

Mixins

Page 10: React talk, GrunnJs 24 September 2014

Composability

Page 11: React talk, GrunnJs 24 September 2014

JSX

Page 12: React talk, GrunnJs 24 September 2014

CJSX

Page 13: React talk, GrunnJs 24 September 2014

Rendering

• Rendering everything is conceptually simple

• render() is called every time state/props change

• Naive implementation would be really slow

Page 14: React talk, GrunnJs 24 September 2014

Credits: Christopher “vjeux” Chedeau

Page 15: React talk, GrunnJs 24 September 2014

Credits: Christopher “vjeux” Chedeau

Page 16: React talk, GrunnJs 24 September 2014

Best practices• Minimize state

• Isolate state to a logical place in a component

• Do not mutate the DOM directly.

• Think of components as state machines

• Pass props in one direction, use callbacks

Page 17: React talk, GrunnJs 24 September 2014

Integration

• Most components should only contain display logic

• Use a root component that does orchestration

• Use another place to do that (`Backbone.Router`)

Page 18: React talk, GrunnJs 24 September 2014

Existing plugins• Some lifecycle methods:

componentDidMount()  

componentDidUpdate()

componentWillUnmount()

• getDomNode()

• refs

Page 19: React talk, GrunnJs 24 September 2014

perfectScrollbar

Page 20: React talk, GrunnJs 24 September 2014

–Brendan Eich

“I also like things about React, which is in some ways less ambitious because React just says, “We’re the view. You can use us with Ember or

Angular.”” !

“And the view, there are various ways to skin that cat and I like the React way of using virtual

DOM diffing and immutability.”

http://javascriptjabber.com/124-jsj-the-origin-of-javascript-with-brendan-eich/

Page 21: React talk, GrunnJs 24 September 2014

`logout`