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

reusing logic in vue and in react

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

reusing logic in vue and in react

Reusing logic in vue and in react by Jesse Chen @JSDC 2019/10/26 https://2019.jsdc.tw/agenda.html

Avatar for LINE Developers Taiwan

LINE Developers Taiwan PRO

October 26, 2019
Tweet

More Decks by LINE Developers Taiwan

Other Decks in Programming

Transcript

  1. concerns for HOC • still has name clashes • a

    lot of conventions • caveats need to be taken care of • For more information:
 https://reactjs.org/docs/higher-order-components.html#use-hocs-for-cross-cutting- concerns
  2. render props pros • only one caveat (when using it

    with React.PureComponent) • Top-down dependencies is clear in the render tree • it’s a technique not a new api, it works exactly the same as a normal component • HOC: the argument is not props but a component • Mixin: doesn’t render
  3. render props cons • one extra level in devTool after

    reusing a logic • same situation for HOCs
  4. the answer is yes • Install @vue/babel-preset-jsx • Rewrite your

    <template> into JSX like syntax inside component’s render function
  5. HOC & render props in vue.js • HOC: more things

    need to be passed down • Slots • v-on • render props: any component renders render props component needs to be rewrite in JSX-like syntax
  6. reuse stateful logics • mixins: very flexible, but also introduce

    troubles when the app scale and complexity raised • HOCs: many conventions and caveats / wrapper hell • render props: JSX specific / wrapper hell • hooks: a new way of thinking when writing web apps