Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

8664 bites

Page 34

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.

React & Next.js2 min read

When would you choose Redux or Zustand over React's built-in hooks?

Choose global state when many components share rapidly changing state, logic is complex, or updates must be traceable.

React's useFormStatus: Read Form State from a Child Component
React & Next.js2 min read

React's useFormStatus: Read Form State from a Child Component

The useFormStatus hook lets a child component read its parent form's submission status without prop drilling. Use it to disable a submit button or show a loading spinner from within a reusable component.

React & Next.js2 min read

How do Redux actions, reducers, and click-to-render data flow work?

Tests Redux unidirectional flow and immutability. Strong answer: actions are plain event objects, reducers are pure functions returning new state, and flow goes dispatch to store to UI. Red flag: actions mutating state or reducers with side effects.

React Refs: An Escape Hatch for DOM Manipulation
React & Next.js2 min read

React Refs: An Escape Hatch for DOM Manipulation

A ref is an escape hatch to directly access a DOM node, bypassing React's declarative state flow. Use it for imperative actions like focusing an input or scrolling to an element. The footgun: overusing refs can conflict with React's rendering.

React & Next.js2 min read

How do you select a single property and prevent extra re-renders?

Tests selector granularity and reference equality in subscriptions. Great answer: return a primitive via a focused selector; for objects, memoize with createSelector or pass shallowEqual. Red flag: reaching for useMemo or React.memo before fixing the selector.

React.memo: Skip Unnecessary Component Renders
React & Next.js2 min read

React.memo: Skip Unnecessary Component Renders

React.memo tells a component to skip re-rendering if its props are the same as last time. Use it to prevent costly renders when a parent updates. The footgun is passing new objects or functions as props, which breaks the default shallow comparison.

React & Next.js2 min read

How would you handle an async API call in Redux Toolkit versus Zustand?

Tests structured async state machines versus lightweight patterns. A strong answer contrasts createAsyncThunk's pending/fulfilled/rejected lifecycles with Zustand's direct set() in async functions, noting Redux's traceability trade-off.

React.lazy: Load Components On Demand
React & Next.js2 min read

React.lazy: Load Components On Demand

React.lazy tells your app: "Don't download this component's code until it's needed." It's a core tool for code splitting. Use it for below-the-fold content or modals to speed up initial load. The footgun: forgetting <Suspense> will crash your app.

Explain atomic state management and how it differs from Redux
React & Next.js2 min read

Explain atomic state management and how it differs from Redux

This tests bottom-up vs top-down architecture. Good response contrasts atom graphs with Redux's monolithic store, notes atoms avoid extra rerenders sans selectors, and flags granular subscriptions.

React Suspense: Manage Loading States Declaratively
React & Next.js2 min read

React Suspense: Manage Loading States Declaratively

React Suspense lets you declare a loading UI instead of manually toggling isLoading state. You wrap a component that fetches data and provide a fallback, letting React handle the switch. The footgun is that re-fetching can jarringly show the fallback again.

React & Next.js3 min read

What is state hydration in Next.js SSR with Redux or Zustand?

Hydration attaches listeners to server HTML; serialize state to an escaped script tag; boot client store before React or markup is discarded.

React DevTools Profiler: Find Performance Bottlenecks
React & Next.js2 min read

React DevTools Profiler: Find Performance Bottlenecks

The React Profiler records how long components take to render, helping you find performance bottlenecks. Use it to diagnose slow interactions and see which components re-render too often.

React & Next.js2 min read

How does React Testing Library's guiding principle influence query choice?

This tests whether you prioritize user-visible attributes over implementation details when selecting queries. A strong answer ranks getByRole, label, and text above testId because users interact with meaning, not data attributes.

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.

How would you unit test a React title component?
React & Next.js2 min read

How would you unit test a React title component?

This tests React Testing Library's user-centric approach and Jest basics. A strong answer renders the component, queries the h1 by role or text, and asserts it is in the document. A red flag is using Enzyme shallow rendering or testing internal state.

React & Next.js2 min read

Bundle Analysis: An X-Ray for Your App's Weight

Bundle analysis is an X-ray for your compiled JavaScript, showing which libraries contribute to your app's final size. Use it to diagnose slow loads by finding large or duplicated dependencies. The footgun: focus on gzipped size, not raw size.

React & Next.js2 min read

What are fireEvent and user-event, and why prefer user-event?

FireEvent triggers single DOM events; user-event simulates full interactions with focus checks. Prefer user-event.

React & Next.js2 min read

Next.js SSG: Pre-render Pages for Maximum Speed

Next.js's Static Site Generation (SSG) pre-renders pages into static HTML at build time, serving them instantly from a CDN. It's ideal for content that rarely changes, like blog posts, ensuring top performance. The main pitfall is serving stale data.

React & Next.js2 min read

Test a React component fetching async data on mount

Whether you can assert on asynchronous DOM updates without race conditions. Mock the API, render, then use findBy or waitFor to assert on loading and loaded states. Red flag: using getBy right after render or forgetting to await async queries.