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

Hello World 2018 - We need to talk about Preact

Hello World 2018 - We need to talk about Preact

Hello World Tech Conference

February 15, 2018
Tweet

More Decks by Hello World Tech Conference

Other Decks in Programming

Transcript

  1. HELLO! I am Sara I work at YLD and make

    useless stuff on the internet @NikkitaFTW
  2. 1. What ? 2. Who ? 3. Why ? 4.

    Future ? 5. The CLI
  3. X KB OF JS IS NOT THE SAME AS X

    KB OF IMAGES The browser has to download it but also parse it and in older devices this may be the biggest problem
  4. yarn add preact-compat { // ... resolve: { alias: {

    'react': 'preact-compat', 'react-dom': 'preact-compat', // Not necessary unless you consume a module using `createClass` 'create-react-class': 'preact-compat/lib/create-react-class' } } // ... } How ?
  5. CONTEXT In some cases, you want to pass data through

    the component tree without having to pass the props down manually at every level. You can do this directly in with the “context” API.
  6. class Home extends Component { constructor() { super(); this.state =

    { loading: true } } render = () => { const { name } = this.props; const { loading } = this.state; return ( <div> {loading ? ‘Loading...’ : name} </div> ) } }
  7. class Home extends Component { state = { loading: true

    } render = ({ name }, { loading }) => ( <div> {loading ? ‘Loading...’ : name} </div> ) }
  8. CSS CLASS You can just use class for CSS classes.

    className is still supported, but class is preferred.
  9. SYNTHETIC EVENTS Preact's browser support target does not require this

    extra overhead. Preact uses the browser's native addEventListener for event handling