Skip to content
tezvyn:

React

262 bites tagged React — interview questions with model answers, and 60-second explainers.

React & Next.js2 min read

How does children work, and why is it fundamental to composition?

Tests React composition knowledge. Good answer: children is a prop holding nested JSX; a Card wrapper renders {children} to let parents inject markup; contrast with prop-driven text. Red flag: calling children magic syntax instead of a standard prop.

React & Next.js2 min read

What is prop drilling in React?

Define it as threading props through middle layers; give a three-layer example like a theme toggle; cite useContext. Awareness of coupling when props tunnel through indifferent layers. Using Context for every prop.

React & Next.js2 min read

Why is exhaustive-deps critical and when can you disable it?

This tests closure and effect timing intuition. A strong answer explains missing deps let effects read stale render values, gives a concrete override like a ref or stable callback, and warns that silencing the rule hides refactor hazards.

React & Next.js2 min read

When would you choose useLayoutEffect over useEffect?

Use useLayoutEffect to measure or mutate DOM before paint to stop flicker; useEffect runs after paint. React commit phase and paint timing. Using it for data fetching or ignoring its blocking cost.

React & Next.js2 min read

Why pass a function to useState for expensive initial values?

This tests your understanding of React's render-phase behavior. Without the function, expensive work reruns on every render and is thrown away; the initializer runs once only during mount.

React & Next.js2 min read

What is the purpose of the useEffect cleanup function?

Explain cleanup prevents memory leaks by clearing timers or unsubscribing when dependencies change or on unmount. Your grasp of useEffect teardown before re-runs and unmount.

React & Next.js2 min read

How do you fetch data with useEffect and prevent memory leaks?

This tests useEffect async lifecycle and cleanup. A good answer places fetch inside useEffect, uses an ignore flag or AbortController to block state updates after unmount, and includes deps. A red flag is skipping cleanup and letting a late response set state.

React & Next.js2 min read

What will count be after three setCount calls in a row?

Tests React state batching and stale closures. Answer: count is 1 because all three calls read the same closed-over value of 0. Fix: pass an updater function setCount(c => c + 1) three times so React queues each update.

React & Next.js2 min read

Explain useEffect dependency array behavior for [], [deps], and omitted

It tests reactive dependency tracking. Omitting re-runs every render; [] runs on mount with cleanup on unmount; [deps] re-runs when Object.is detects change. Red flag: claiming [] means 'run once' without mentioning cleanup or stale values.

React & Next.js2 min read

How do you use useState to track user input?

Initialize with useState at top level, bind input value to state, and update via onChange using setter. Whether you know useState basics for controlled inputs. Calling useState conditionally or mutating state directly.

React & Next.js2 min read

Can you pass a React component as a prop? Explain Render Props.

Tests React composition. Yes, functions and JSX are valid prop values. Strong answers explain inversion of control, contrast with children, and cite dynamic layouts. Red flag: conflating render props with HOCs or saying props only accept primitives.

React & Next.js2 min read

How does React use keys in reconciliation? When do keys cause bugs?

Tests reconciliation identity semantics. Answer: keys give scoped identity for O(n) diffing; stable keys preserve state, but indices during reordering make React reuse DOM nodes wrongly, polluting state. Red flag: saying keys are 'just for performance'.

React & Next.js2 min read

Write the React.createElement() equivalent for this JSX

Tests JSX-to-JS compilation mechanics. Answer: createElement('a', {href: '/home', className: 'link'}, 'Go Home'). Children must be the third argument, not inside props. Red flag: nesting children in props or using an unquoted tag variable.

React & Next.js2 min read

Explain prop drilling and why it's a problem

Tests coupling in deep React trees. Good answers define prop drilling as forwarding props through unused intermediaries, cite coupling and refactor pain, and name Context or composition as fixes. Red flag: calling props bad or jumping to Redux without Context.

React & Next.js2 min read

What is a React Fragment and why use it over a div?

This tests JSX semantics and DOM hygiene. A strong answer says Fragments group children without wrapper nodes, preventing extra DOM and invalid HTML like divs in tables. A red flag is citing performance without mentioning DOM structure or semantics.

React & Next.js2 min read

Describe two patterns for conditional rendering in JSX

First, early return with if/else for branches; second, ternary or logical AND inside JSX for inline toggles. Whether you know React conditional rendering. Reaching for useState or useEffect when simple JS suffices.

React & Next.js2 min read

What is the purpose of React's key prop and index key risks?

This tests React reconciliation. Keys give stable identity to match components across renders and preserve state. Indices break on reorder or delete, causing state bugs. A red flag: saying keys are only for performance or indices are harmless.

React & Next.js2 min read

What are the two main ways to define a component in React?

Tests fluency in function and class syntax. Outline: show a function returning an h1; show a class with render() returning an h1; note functions are the React 19 default. Red flag: offering arrow vs function declaration as the two ways, or omitting render().

React & Next.js2 min read

Explain props in React and how parent components pass data to children

Define props as the single object argument; show destructuring; stress immutability and downward flow; note defaults. Your grasp of props as the read-only, one-way parent-to-child interface.

React & Next.js2 min read

Zustand Middleware: Intercept Every Set Call

Zustand middleware intercepts set calls to add logging, persistence, or devtools without touching business logic. Use it when updates need the same side effect, like localStorage sync.

React & Next.js2 min read

Accessible React Forms: Labels, Focus, and Errors

Accessible React forms need real labels, keyboard focus, and error announcements, not just ARIA. Screen reader users must perceive inputs and validation without visual cues. The common footgun is placeholder text or divs instead of label elements with htmlFor.

React & Next.js2 min read

HashRouter: routing without server configuration

HashRouter traps routes after a # the server never sees, letting SPAs run on static hosts like GitHub Pages without rewrite rules. The tradeoff is ugly URLs and SEO blind spots since search engines may ignore whatever follows the hash.

React & Next.js2 min read

BrowserRouter: Real URLs in React SPAs

BrowserRouter turns the address bar into a client-side navigation system, using real URLs without reloads. It is the default choice for SPAs that need shareable links.

React & Next.js2 min read

BEM: Self-Documenting CSS Class Names

BEM turns classes into a mini filesystem: Block__Element--Modifier. It prevents CSS collisions in large React codebases where many teams share a global stylesheet. The footgun is turning every nested tag into an element and creating comically long names.

Get React bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.