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

React and TypeScript

React and TypeScript

A small talk my colleague Joppe (http://apestaartje.info/) and I gave at a development clinic for my colleagues at Zicht Online.

It explains a bit about TypeScript and React.

Robert van Kempen

January 18, 2017
Tweet

More Decks by Robert van Kempen

Other Decks in Programming

Transcript

  1. Transpiling ▪ ES5 works in all modern browsers ▪ Previously

    Babel, now TypeScript ◦ Backed by big organisation and community ◦ Cleaner code ◦ Typed programming ▪ All JavaScript = valid TypeScript
  2. SystemJS Universal dynamic module loader - loads ES6 modules, AMD,

    CommonJS and global scripts in the browser and NodeJS.
  3. Loading modules import Backbone from 'backbone'; Works when: ▪ TypeScript

    compiler knows what Backbone is ▪ SystemJS knows what Backbone is
  4. Loading modules ▪ Loading modules in ES5 requires <script> tags

    ▪ TypeScript compiles to your preferred loader format ◦ AMD ◦ UMD ◦ CommonJS ◦ SystemJS ▪ SystemJS is built on top of a polyfill of ES Loader API
  5. Transpiled result ▪ Own code is imported with a relative

    path ▪ Vendor code is imported with a name
  6. SystemJS configuration ▪ system.conf.js ▪ defaultJSExtensions can be used to

    rewrite paths ▪ Globals like Backbone should be configured
  7. Static type checking const x = 4; const y =

    “melp”; const add = x + y; // won’t compile
  8. Extra data types Tuples: type Data:[string, number]; const x:Data =

    [‘hodor’, 666]; Type Data2:[string, number]; const y:Data2 = [666, ‘hodor’]; // won’t compile
  9. What is React? A JavaScript library ▪ Created by Facebook

    ▪ Used by Netflix, Instagram, Dropbox ...
  10. Stateless components Components without a class. const Button = (props)

    => { return ( <button type={props.type}>{props.children}</button> ) } export { Button }
  11. Separation Separates behaviour and UI. ▪ State can be managed

    by other parts of the app, like a component or Flux/Redux. ▪ It’s easy to build UI libraries.
  12. cxs import cxsAtomic from 'cxs' const styles = { padding:

    16, color: 'tomato', ':hover': { color: 'orangered' }, '@media (min-width: 40em)': { padding: 32 } } cxsAtomic(styles) // p-16 c-tomato -hover-c-orangered _zsp35u
  13. Cool stuff ▪ React Native Mobile apps ▪ React +

    ElectronJS Desktop apps like Slack ▪ Rebass UI Component Library
  14. React reading ▪ https://github.com/timarney/react-faq A collection of links to help

    answer your questions about React ▪ https://reactforbeginners.com/ Online video course ▪ https://github.com/enaqx/awesome-react A collection of awesome things regarding React ecosystem
  15. TypeScript reading ▪ https://www.typescript-weekly.com/ Weekly newsletter with TypeScript links ▪

    https://github.com/dzharii/awesome-typescr ipt A collection of awesome TypeScript resources for client-side and server-side development