useBreakpoints: a hook

Mae Capozzi · February 15, 2019

I built my first hook a few months ago, and figured I should get it up on the blog. It's a replacement for a Higher Order Component that exists in a codebase I'm working on. That HoC passes a breakpoint to a component that dictates how the component renders across different breakpoints.

If you want to play around with the component, you can find it on Code Sandbox. I'll also briefly walk you through how it works.


The first thing useBreakpoints does is set set the state. useState lets you use React local state even when you're not in a class. To use it, you destructure an array, in which the first argument is whatever you want to call it, and the second lets you update the state (much like this.setState).

In this hook, when a user resizes the screen, I set a new width on state with the setWidth function inside of useEffect. useEffect lets you use something like lifecycle methods when you're not in a class. In other words,I reset the state with a new width. Then, I pass that new width to my setBreakpoints function, which returns the correct breakpoint based on the size of the browser window.

Continue Reading

aitypescriptdeveloper-tools

Tooling migrations don't have to take weeks anymore

I used to block out weeks for tooling migrations. Now I let Claude Code run in the background, check in when it's done, and pair with it to understand what changed.

Read Post
frontend platformsystems thinkingobservability

Frontend Technical Debt Is a Business Problem

Frontend technical debt doesn't just slow down developers. It undermines your entire business through user attrition, legal risks, and revenue loss. Here's how to spot and communicate these hidden costs.

Read Post
aideveloper-tools

AI-Assisted Dependency Review

How I used Conductor and Claude to streamline my team's Dependabot review workflow — and how a colleague turned it into a GitHub Action

Read Post