Skip to content
tezvyn:

Search

Find a bite, explore a topic or look for a role.

Results for React

Bites 747

React & Next.js2 min read

Cypress for End-to-End Testing in Next.js

Cypress is a framework for end-to-end testing of Next.js applications. It's presented as a primary option in the official docs, alongside tools like Playwright and Vitest, for automating tests that simulate real user interactions in a browser.

Snapshot Testing: Lock In Your UI's Rendered Output
React & Next.js2 min read

Snapshot Testing: Lock In Your UI's Rendered Output

Snapshot testing catches unintended UI changes by comparing a component's rendered output to a saved 'golden' version. Use it to ensure UIs don't break during refactors. The biggest footgun is blindly updating snapshots, which can approve bugs as correct.

React & Next.js2 min read

user-event vs. fireEvent: Testing Real User Interactions

user-event tests how users actually interact with your UI, not just isolated DOM events. It simulates a full action sequence, like a click firing pointerdown, mousedown, and click. Use it to test component behavior from a user's perspective.

React & Next.js2 min read

RTK Query: Your Redux Data Fetching Layer

RTK Query treats server data as a cache, not global state, handling fetching and loading states for you. Use it to replace manual fetch logic and keep data fresh across components. Forgetting to call setupListeners disables automatic refetching.

React & Next.js2 min read

Redux: Actions are Events, Reducers are Event Handlers

Redux Actions are events describing *what* happened (e.g., 'task added'), while Reducers are functions that specify *how* state changes in response. This pattern is central to managing global state. The biggest footgun is mutating state directly in a reducer.

React & Next.js2 min read

Tree Shaking: Shipping Only the Code You Use

Tree shaking is a build step that eliminates unused code from your final bundle. Bundlers like webpack use it to shrink JavaScript files by removing functions you import but never call.

React & Next.js2 min read

List Virtualization: Render the Window, Not the World

Virtualization renders only the visible "window" of a long list, not the entire dataset. It's essential for performance in feeds or tables with thousands of rows.

useFormState (now useActionState): State for Actions
React & Next.js2 min read

useFormState (now useActionState): State for Actions

useActionState (formerly useFormState) lets you update state from an async Action. It returns the action's result, a dispatch function, and a pending status. Use it to manage form UI for loading states and validation messages from Server Actions.

Zod: Validate Data, Infer Types
React & Next.js2 min read

Zod: Validate Data, Infer Types

Zod acts as a bouncer for your data, validating it against a schema you define and inferring TypeScript types automatically. It's essential for validating API inputs or form submissions. The main footgun is forgetting to enable "strict": true in your tsconfig.

Nested Routes: Composing UI with <Outlet>
React & Next.js2 min read

Nested Routes: Composing UI with <Outlet>

Nested routes build layouts with shared UI, like a sidebar. The <Outlet> component is a placeholder for changing content, perfect for dashboards. The footgun is forgetting the <Outlet> in the parent route; child routes will match the URL but won't render.

useDeferredValue: Keep UI Responsive During Renders
React & Next.js2 min read

useDeferredValue: Keep UI Responsive During Renders

useDeferredValue keeps your UI responsive by showing a stale value while a new, expensive-to-render value is prepared in the background. Use it for search inputs filtering large lists.

useTransition: Keep Your UI Responsive During State Changes
React & Next.js2 min read

useTransition: Keep Your UI Responsive During State Changes

useTransition lets you update state without blocking the UI, keeping your app responsive. Use it for slow renders like filtering large lists, while the isPending flag shows a loading state.

React & Next.js2 min read

next/dynamic: Defer Loading Heavy Components

next/dynamic splits a component into its own file, loading it only when needed to shrink your initial bundle. Use it for heavy components below the fold or browser-only libraries. The footgun: forgetting a loading state causes layout shifts.

React & Next.js2 min read

Next.js Layouts: Shared UI That Survives Navigation

Think of a Next.js Layout as a picture frame that stays put while you swap the pictures (Pages) inside. It defines shared UI like headers that persist across routes, preserving state.

React & Next.js2 min read

Compound Components: Build Flexible APIs via Shared State

Think of HTML's <select> and <option>. The Compound Component pattern lets a parent manage state while children act as declarative configuration. It's used for flexible UI like tabs or accordions.

useImperativeHandle: Expose a Custom Ref API
React & Next.js2 min read

useImperativeHandle: Expose a Custom Ref API

useImperativeHandle exposes a custom API via a ref, letting a parent call specific methods on a child. Instead of exposing an entire DOM node, you can provide a handle with methods like reset() or focus().

useLayoutEffect: Synchronous Effects Before Browser Paint
React & Next.js2 min read

useLayoutEffect: Synchronous Effects Before Browser Paint

useLayoutEffect is useEffect's synchronous twin, running its code after DOM mutations but before the browser repaints. Use it to read DOM layout and re-render to prevent visual flickers, like positioning a tooltip. Its main footgun: it blocks rendering.

The useReducer Hook: Predictable State Updates
React & Next.js2 min read

The useReducer Hook: Predictable State Updates

useReducer is a state machine for your components, managing complex state changes predictably. Use it when state logic is complex or the next state depends on the previous one, like in a shopping cart.

Custom Hooks: Package Component Logic for Reuse
React & Next.js2 min read

Custom Hooks: Package Component Logic for Reuse

A custom hook packages stateful logic (like useState and useEffect) into a reusable function. Use one when multiple components need the same logic, like tracking online status for a status bar and a save button. Footgun: Names must start with use.

useState: Giving Components Memory
React & Next.js2 min read

useState: Giving Components Memory

useState gives a component its own memory, letting it track information that changes over time. It's used for everything from handling form input to toggling UI. The biggest footgun: state updates are asynchronous and only apply on the next render.