Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Inside React: Then and Now

Tianyu Pu
November 16, 2018

Inside React: Then and Now

React is a popular library for building user interfaces, well-known for encouraging the breakdown of code into components, as well as declarative rendering (especially in conjunction with ES6). What's less well-known is how it works under the hood. In this talk we'll go into the guts of React, how it actually works, what React Fiber is, why it was necessary, and how it affects React applications going forward.

Tianyu Pu

November 16, 2018
Tweet

More Decks by Tianyu Pu

Other Decks in Technology

Transcript

  1. <div> <button onClick={() => this.setState({ })} >Click me!</button> <p>{this.props.text}</p> </div>

    class SillyDiv extends React.Component { render() { return ( ...
  2. <div> <button onClick={() => this.setState({ text: new Date().toString() })} >Click

    me!</button> <p>{this.props.text}</p> </div> class SillyDiv extends React.Component { render() { return ( ...
  3. <div> <button onClick={() => this.setState({ text: new Date().toString() })} >Click

    me!</button> <p>{this.props.text}</p> </div> class SillyDiv extends React.Component { render() { return ( ...
  4. <div> <button onClick={() => this.setState({ text: new Date().toString() })} >Click

    me!</button> <p>{this.state.text}</p> </div> class SillyDiv extends React.Component { render() { return ( ...
  5. <div> <button onClick={() => this.setState({ text: new Date().toString() })} >Click

    me!</button> <p>{this.state.text}</p> </div> class SillyDiv extends React.Component { render() { return (
  6. function mount(component) { if (host component) // create DOM node

    // mount children if (composite component) // call render() of component // mount the result of render() }
  7. class DOMComponent { currentElement renderedChildren node mount() receive(nextEl) } class

    CompositeComponent { currentElement renderedElement publicInstance mount() receive(nextEl) }
  8. function receive(nextEl) { // figure out next rendered element //

    if same type, call receive() // otherwise, make changes }
  9. function receive(nextEl) { // figure out next rendered element //

    if same type, call receive() // otherwise, make changes }
  10. function receive(nextEl) { // figure out next rendered element //

    if same type, call receive() // otherwise, make changes }
  11. { }