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

Introduction to React.js

Introduction to React.js

Yusuke Higashi

July 05, 2016
Tweet

Other Decks in Technology

Transcript

  1. What is problem in web application development? • Separate HTML

    and logic(JavaScript) • Managing DOM is difficult. • DOM has state. • DOM like a global variable • Anyone can update it anytime. • We consider asynchronous action • Ajax
  2. Example: TODO application(jQuery) HTML JavaScript <- Todo counter If count

    value is changed by other logic, this logic is broken.
  3. Example: TODO application(jQuery) HTML JavaScript We need to manage state

    of DOM for adding and changing function. Maintenance is so difficult…....
  4. How do we resolve this problem. • One of solutions

    about managing DOM state is update all DOM. • Manage state in JavaScript. • If state is changed, updating all DOM • You don’t concern DOM state.
  5. Image of update all DOM <Javascript> counter = 1 tasks

    = [‘task1’] All DOM are updated.
  6. Image of update all DOM <Javascript> counter = 2 tasks

    = [‘task1’,’task2’] All DOM are updated again.
  7. But…. • Updating all DOM is very slow…. • If

    there is many DOM elements, update cost is BIG.
  8. What is React.js? • It is made by Facebook. •

    JavaScript library for UI • React.js provide view function. • React.js has virtual DOM • Calculate diff between DOM and virtual DOM • React.js update only diff. • Component-based • ”Its goal is to be simple, devlarative and composable.” (from wikipedia)
  9. Virtual DOM • React.js can render only diff using Virtual

    DOM • It is on Javascript. • Calculate diff between current DOM and new DOM. • Update only diff • Updating cost is small.
  10. Real DOM(Browser) Virtual DOM Virtual DOM Current DOM New DOM

    Calculate diff between current and new.
  11. How virtual DOM change our programming style ? • We

    can adapt updating all DOM programing style. • We don’t concern state of current DOM. • React.js update diff automatically. we don’t need to concern diff.
  12. Component-based • React.js is component based. • You can define

    component which like a custom tag. • Component has state and logic and view. • Data flow is simple. • Parent components send data to child components.
  13. Component-based TodoForm Initial state Update state. Execute parent method. View(HTML)

    Render child components and send state to child components
  14. Conclusion • We can adapt updating all DOM programing style.

    • We don’t concern state of current DOM. • Component oriented • state, logic and view are involved. • Data flow is simple. • Parent component send to child component.