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

Demystifying React Hooks

Avatar for thereactboy thereactboy
September 21, 2019

Demystifying React Hooks

A deeper dive into the world of React Hooks and my experience on migrating from a complex class-based react codebase to using react hooks in it and what were it's implications. Looking at React Hooks from a different perspective and how is it a Boon or Bain for ReactJS devs.

Avatar for thereactboy

thereactboy

September 21, 2019
Tweet

More Decks by thereactboy

Other Decks in Programming

Transcript

  1. Tathagat Thapliyal • Co-Founder @ Voz, A content community platform.

    thevoz.in • Software Developer and Mentor at Coding Blocks. • Student, Thapar University, Patiala.
  2. What are react hooks? A react feature that lets you

    use state and lifecycles without writing a class based react component.
  3. Class based component Most forgetful and toughest error to figure

    out for beginners Might need to duplicate this in some other component Code smelling all over the place
  4. So What? ‍♂ HOCs Render Props Hooks Reuse Stateful Logic

    ✅ ✅ ❓ Explicit Props ❌ ✅ ❓ Composability ✅ ❌ ❓ No “Wrapper Hell” ❌ ❌ ❓
  5. SPOILER ALERT!! HOCs Render Props Hooks Reuse Stateful Logic ✅

    ✅ ✅ Explicit Props ❌ ✅ ✅ Composability ✅ ❌ ✅ No “Wrapper Hell” ❌ ❌ ✅
  6. Some Hooks API Similar to componentDidMount and componentDidUpdate. Piece of

    state is referred by this variable. To use the piece of state inside functional component. Similar to this.setstate({})
  7. More Hooks API’s Basic Hooks • useState() • useContext() •

    useEffect() Advanced Hooks • useReducer() • useCallback() • useEffect() • useMemo() • useRef()
  8. Conclusion ? • Easier to work with . • Easier

    to test. • More readability. • Few lines of code. • No new component formation on DOM.