Discover the advantages of React Hooks over class components! The hosts break down how Hooks decouple UI from logic for better modularity. They highlight a reduction in code complexity with useEffect, making lifecycle management a breeze. Learn about targeted control over side effects and the simplicity of managing state with user-friendly syntax. Explore the challenges of asynchronous patterns and get insights on emerging state management libraries that streamline development. Perfect for anyone looking to elevate their React skills!
25:35
forum Ask episode
web_stories AI Snips
view_agenda Chapters
auto_awesome Transcript
info_circle Episode notes
insights INSIGHT
Decoupling UI and Logic
React Hooks decouple UI from logic, enabling reusable logic blocks.
This allows sharing functionality across components and projects like Lego blocks.
insights INSIGHT
Improved Code Reusability
Reusing functionality improves code quality and understandability.
Pre-built hook libraries like "re-hooks" and GraphQL codegen become possible.
insights INSIGHT
Simplified State and Functionality Management
Hooks simplify managing multiple state pieces and functionalities.
Avoid complex render props or higher-order components for cleaner code.
Get the Snipd Podcast app to discover more snips from this episode
In this Hasty Treat, Scott and Wes talk about React Hooks and why you might want to use them instead of class components.
Sentry - Sponsor
If you want to know what’s happening with your errors, track them with Sentry. Sentry is open-source error tracking that helps developers monitor and fix crashes in real time. Cut your time on error resolution from five hours to five minutes. It works with any language and integrates with dozens of other services. Syntax listeners can get two months for free by visiting Sentry.io and using the coupon code “tastytreat”.
Show Notes
03:54 - Decouple the UI from the logic
This wasn’t impossible with class-based components, but we started using HOC to do this.
With hooks, it makes you decouple what it does and how it looks.
Makes things like GraphQL code gen possible
Multiple pieces of state or functionality
Share commonly used functionality among projects and components
10:31 - Reduction in code
Lifecycle methods were often redundant. useEffect offers a way to prevent the duplication that can happen with component did update and did mount. This gives you a way to say, “Hey, run this code when these things change.”
13:30 - useEffect’s dependencies
These give you access to targeted control over side effects rather than just something changed.
14:15 - Easier to grok
What happens? When? Where? It’s mostly in the hook.
16:09 - Simplicity in usage
Thing, updateThing is more targeted than set state
Ref makes way more sense with useRef
String refs weren’t great, the function ref thing was obnoxious