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.

4330 bites

Page 15

Can you pass a React component as a prop? Explain Render Props.
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.

How do you use useState to track user input?
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.

Explain useEffect dependency array behavior for [], [deps], and omitted
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.

What will count be after three setCount calls in a row?
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.

How do you fetch data with useEffect and prevent memory leaks?
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.

What is the purpose of the useEffect cleanup function?
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.

Why pass a function to useState for expensive initial values?
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.

When would you choose useLayoutEffect over useEffect?
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 & 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.

What is prop drilling in React?
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.

How does children work, and why is it fundamental to composition?
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.

What is a custom hook? Write a simple useToggle example.
React & Next.js2 min read

What is a custom hook? Write a simple useToggle example.

What it tests: Whether you see hooks as stateful logic extraction. Outline: Define a use-prefixed function calling hooks; write useToggle with useState and callback; explain extraction vs duplication. Red flag: Helpers without hooks or missing use prefix.

Explain useReducer and when to prefer it over useState
React & Next.js2 min read

Explain useReducer and when to prefer it over useState

Tests if you know useReducer centralizes complex state transitions better than scattered useState. Answer: define reducer/dispatch, then contrast with useState via interdependent fields or deep updates. Red flag: calling it only for global state or Redux.

Use useContext to provide theme state without prop drilling
React & Next.js2 min read

Use useContext to provide theme state without prop drilling

This tests global state sharing without prop drilling. A strong answer uses createContext and a Provider with useState at the app root, then calls useContext in nested components. Red flag: ignoring re-render costs or placing the Provider too deep.

Explain the difference between useMemo and useCallback
React & Next.js2 min read

Explain the difference between useMemo and useCallback

This tests whether useMemo caches values while useCallback caches functions, and why that matters for React.memo. A strong answer notes React.memo uses Object.is, so a new inline function prop triggers a child re-render. Red flag: claiming they are the same.

Compare HOCs and custom hooks for sharing logic
React & Next.js2 min read

Compare HOCs and custom hooks for sharing logic

Tests your grasp of React's shift from wrapper-based to function-based logic reuse. Hooks eliminate wrapper hell and implicit props by extracting stateful behavior into plain functions without nesting components. Red flag: calling hooks just sugar.

Describe combining useContext and useReducer for scalable feature state
React & Next.js2 min read

Describe combining useContext and useReducer for scalable feature state

This tests replacing prop drilling with a context-reducer pattern. A strong answer covers two contexts for state and dispatch, a provider wrapping the subtree, and a pure reducer. A red flag is one global context or async logic inside the reducer.

React & Next.js2 min read

Pass server-fetched data from Server Components to nested Client Components

Tests RSC boundary awareness. Strong answer: fetch in the async Server Component, pass serializable props to nested Client Components. Red flag: proposing Context or useEffect inside the Server Component.

What is a stale closure in React hooks?
React & Next.js2 min read

What is a stale closure in React hooks?

Tests closures and hook dependencies. A strong answer defines stale closure as capturing an outdated variable, shows a useEffect interval with stale state, and fixes it with dependencies and cleanup. Red flag: omitting cleanup or using refs blindly.

React & Next.js2 min read

How do CSS Modules solve global scope conflicts in React?

This tests build-time hashing and local scope. An answer explains that CSS Modules compile classes into unique hashes, scoping styles to the component, and shows the React import pattern styles.primary.