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

Introduction to React (WildHacks 2016)

Introduction to React (WildHacks 2016)

Avatar for Timotius Sitorus

Timotius Sitorus

November 19, 2016

Other Decks in Programming

Transcript

  1. React is… • JavaScript library created by Facebook • Used

    to make Dynamic Web Applications • Open Source • The 5th most starred repo on GitHub
  2. Build Components, not templates • UI components are composed together

    • UI description and logic are tightly coupled • Full Power of JavaScript to express UI
  3. Elements vs. Components • Elements are your basic building blocks

    (div, li, h1 – h5) • Components are the stuff you build
  4. JSX • Optional HTML-like markup • Declarative description of UI

    inlined in JS code • Combines ease templates with the power of JavaScript • Preprocessor translates to plain JavaScript: • On the fly (suitable during development) • Offline using the React CLI
  5. State vs. Props • Both Props and State are plain

    JS Objects • When Props or State changes, render and update • State à • Internal State of a component • Props à • Passed by a parent component • Used to configure a component • Used to pass data between components
  6. Traditional Performance Best Practices • Avoid Expensive DOM Operations •

    Minimizes access to the DOM • Update elements offline before reinserting into the DOM • Avoid tweaking layouts in JavaScript
  7. Virtual DOM 1. Create lightweight description of the UI 2.

    Diff it with the old one 3. Compute minimal set of changes to apply to the DOM 4. Batch Execute all updates Re-render everything on every update
  8. React Native • Not a “Mobile Web App”, “HTML5 App”

    or “Hybrid App” • Elements that you use to build your components are native • Reload your app instantly with no recompilation • Fantastic DevTools (Ex: Remote Debugging, Systrace, Perf Monitor) • Use Native Code when you need to Learn Once, Write Anywhere
  9. Resources • React à https://facebook.github.io/react/ • Tutorial à https://online.reacttraining.com/p/reactjsfundamentals •

    Rethinking Best Practices à https://www.youtube.com/watch?v=x7cQ3mrcKaY • Create-React-App à https://github.com/facebookincubator/create-react-app • React Native à https://facebook.github.io/react-native/