React | Advanced Problems & Solutions π
Shahzaib Khalid
Stop! π
This is not an introduction to React! πΆ
You must have an idea about:
- Props
- State
- Lifecycle Methods
Who am I? π

A front-end developer π¨π»βπ» mainly interested in JavaScript & React. βοΈ
@shahzaibkhalid | shahzaibkhalid.com
React is Winning! π

But...
There are some pain-points! π
What this talk is about
- Issues with classes in React π’
- How does React Hooks solve problems with classes? π€
- Pain of sharing code among components using HOC & Render Props π
- How does React Hooks simplify code sharing among components? π€
Issues with classes in React
We need to use classes to use state and lifecycle methods
Problem: 01
Classes has annoying behavior when it comes to "this" π’
Problem: 02
Related logic is split across Lifecycle methods π
Problem: 03
You're not sure when you'd be converting functional component to class π€
Problem: 04
Classes are hard to minify and tree-shake πΆ
Problem: 05
Classes makes it difficult to hot-reload your code π
How we can solve these problems with Classes? π€
By avoiding the Classes! Simple. π
React Hooks π
Use State and Lifecycle, straight from simple JavaScript functions!
Hook: 01
useState
It let us hook state into functional components! π
Let's compare Classes with Hooks π₯
But, what to do if I've a state object, instead of a single value?
Hook: 02
useReducer
Inspired by Redux, it let us hook state object into functional component! π
Let's compare Classes vs Hooks for useReducer!
Hook: 03
useRef
Built-in React Hook to access any JSX Element π
Already covered! π
There are many more built-in Hooks! π
But for now, let's discuss problem other than Classes
Sharing stateful logic among React Components πΆ
Sharing stateful logic and sharing code are two different things. βοΈ
How?
Let's understand through an example that what's the meaning of sharing stateful logic?
HOC (Higher Order Component) π€πΌ
But, HOCs can lead us to "Wrapper Hell" π
Render Props to Rescue π
Multiple Render-Props can lead us to "massive nesting" πΆ

(Credits: Nick Gard - Why I Don't Use Render Props in React on Medium)
Custom Hooks are the most exciting features of Hooks! π
No nesting & wrapper hell!
And there are many more Hooks to checkout!
Like, useDarkMode
& useMemo
π