Syntax - Tasty Web Development Treats
Syntax - Tasty Web Development Treats

React Hooks

In this episode Wes and Scott discuss React Hooks - what they are, why you might want to use them, their differences with regular classes, and more. Freshbooks - Sponsor Get a 30 day free trial of Freshbooks at freshbooks.com/syntax and put SYNTAX in the “How did you hear about us?” section. Sentry

Featured Speakers

Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers HostScott Tolinski Guest

Topics Discussed

Episode Summary

Executive Summary: The episode introduces React Hooks as a major new, opt-in API for function components, explaining how they replace common class-component patterns like state, context, effects, and refs. Wes and Scott emphasize cleaner syntax, reusable logic, and incremental adoption, while cautioning listeners to wait for the ecosystem to mature before rewriting production code.

Main Topics: What React Hooks Are and Why They Matter: Hooks let function components use state, context, refs, reducers, and side effects without converting to class components or relying on render props, HOCs, or mixins. useState for Local Component State: The useState hook returns a state value and updater function as an array, enabling multiple independent pieces of state inside a function component with simple destructuring. useContext and Reduced Prop Drilling: useContext simplifies consuming React context by replacing consumer render props, making shared state and functions easier to access and reducing JSX clutter. useEffect for Side Effects and Lifecycle Replacement: useEffect handles side effects such as data fetching, subscriptions, DOM manipulation, and cleanup, covering mount, update, and unmount use cases in one pattern. useReducer, Refs, and Other Specialized Hooks: useReducer provides reducer-style state management for complex updates, while useRef offers a cleaner way to access DOM nodes; other lower-level hooks like useLayoutEffect and useImperativeMethods are discussed as specialized tools. Ecosystem Adoption and Library Opportunities: The hosts highlight early adoption by libraries like Formik, React Spring, Apollo-related tools, and others, arguing that hooks will reshape patterns for forms, animation, global state, and reusable utilities. Caution, Incremental Adoption, and Future Best Practices: Hooks are experimental/alpha at the time of recording, classes are not going away, and the hosts recommend waiting for community patterns and library APIs to stabilize before large-scale rewrites.

Key Arguments: Hooks solve a real pain point: adding state or lifecycle behavior to function components previously required converting them into class components. Hooks are fully opt-in; existing class components and older patterns can continue to work, so teams do not need to rewrite code immediately. useState is cleaner than class state because each state value can have its own updater and be destructured directly into named variables. useEffect unifies mount, update, and unmount side effects, making it easier to organize logic and reuse it across components. useContext removes the need for consumer render props or HOCs when reading shared context values. useReducer and context together cover many of the historical reasons developers adopted Redux, though Redux may still remain useful for some workflows and devtools. useRef provides a practical and cleaner way to interact with DOM elements without relying on magic string refs or unnecessary controlled inputs. The most valuable part of hooks may be the ecosystem they enable: reusable, composable functions for common tasks like data fetching, clicks outside a modal, form handling, animation, and local/global state. The hosts believe best practices are still emerging, so production teams should adopt hooks selectively and watch how the community settles on conventions.

Data Points: React version availability: Alpha version of React 16.7 - At recording time, hooks were only available in an alpha release, not a stable version. Time since release: About a week to a week and a half - The hosts describe hooks as very newly released to the public from Facebook. Sponsor trial length: 30-day unrestricted free trial - FreshBooks offer mentioned in the ad read. Sentry promotional offer: 2 months free - Listeners using the code TASTYTREAT get two months free on Sentry. Error frequency example: About 20,000 occurrences - Scott describes a recurring front-end error seen in Sentry for his Boss Monster application. Affected users example: 7.5,000 people - The same Sentry issue was reported as affecting thousands of users (spoken as 7.5,000). Platform breakdown example: Chrome, Opera, smartphones, Android - Scott uses Sentry to narrow the error down to browser and device patterns. Form of state return: Two values returned in an array - useState returns the current value and an updater function, enabling array destructuring. Redux course status: Old React Create Class API - Wes mentions his existing Redux course still uses older React patterns. Premium course count: 24–25 courses - Wes says Level Up Tutorials has roughly two dozen premium courses by then.

Pivotal Quotes: "Hooks are 100% opt-in and classes aren't going anywhere." — Wes Bos: Used to reassure listeners that adopting hooks does not require rewriting existing React applications. "useEffect is basically how you're going to be writing your own custom hooks." — Scott Tolinski: Explains the central role of useEffect in building reusable hook-based logic. "This is where JavaScript fatigue comes in because they keep changing things." — Wes Bos: A humorous acknowledgment of developer concern about frequent ecosystem changes.

Implications: Hooks make React function components far more powerful and likely become a dominant pattern for new code, but teams should adopt them gradually while libraries and best practices mature.

🔓 Sign Up for Unlimited Episode Search

About Syntax - Tasty Web Development Treats

View all episodes from Syntax - Tasty Web Development Treats