React Developer interview questions
100 real questions with model answers and explanations for Junior candidates.
See a React Developer resume example →Practice with flashcards
Spaced repetition · Hunter Pass
Questions
React is a JavaScript library for building user interfaces from reusable components.
- Developers describe how the UI should look for the current data instead of manually changing DOM nodes.
- Components split an interface into independent pieces with their own inputs and behavior.
- React updates the browser DOM when component data changes.
Why interviewers ask this: The interviewer checks whether you understand React as a declarative UI library rather than a complete application framework.
A React component is a reusable unit that returns the UI React should render.
- A component can receive props from its parent.
- It can hold local state when its output must change over time.
- Components can render browser elements and other components.
Why interviewers ask this: A strong answer identifies a component by its role, inputs, local state, and ability to compose other UI pieces.
A function component is a JavaScript function that React calls to calculate part of the UI.
- Its parameters usually contain props supplied by the parent.
- Its return value is normally JSX, a React element, or null.
- Hooks let function components use state and lifecycle-related behavior.
Why interviewers ask this: The interviewer evaluates whether you can connect an ordinary function shape to React rendering and hooks.
A capitalized JSX tag tells React that the tag refers to a user-defined component.
- Lowercase tags such as div and button are treated as built-in browser elements.
- An uppercase name such as Profile is resolved to a JavaScript variable in scope.
- Using a lowercase component name can make React interpret it as an unknown HTML tag.
Why interviewers ask this: This checks whether the candidate understands how JSX distinguishes custom components from DOM elements.
JSX is a syntax extension that lets JavaScript code describe a React element tree with HTML-like notation.
- JSX is transformed into JavaScript calls or equivalent runtime instructions before execution.
- It can represent both browser elements and custom React components.
- JSX is optional, but it makes nested UI structures easier to read and write.
Why interviewers ask this: The interviewer checks that you do not mistake JSX for HTML or for code the browser executes directly.
JavaScript expressions are placed inside curly braces in JSX.
- Expressions can provide text, prop values, attributes, or child elements.
- Calls, property access, arithmetic, and conditional expressions can produce values inside braces.
- Statements such as if, for, and variable declarations must run outside JSX or be expressed differently.
Why interviewers ask this: A strong answer distinguishes value-producing expressions from statements that cannot be inserted directly into JSX.
JSX uses JavaScript-oriented property names for several browser attributes.
- className is used instead of class because class is a JavaScript keyword.
- Most multiword DOM properties use camelCase, such as tabIndex and onClick.
- String literals can use quotes, while JavaScript values are passed inside curly braces.
Why interviewers ask this: The interviewer checks basic JSX syntax and whether you can pass typed JavaScript values rather than only strings.
A component returns one value representing its element tree, and a Fragment groups multiple siblings without adding a DOM node.
- A wrapper element such as div also creates one root but changes the resulting markup.
- The short Fragment syntax is written as an empty opening and closing tag.
- The explicit Fragment form can receive a key when used in a list.
Why interviewers ask this: A strong answer explains both the single return value and why a Fragment may be preferable to an extra wrapper element.
A component is a function or class definition, while a React element is a description of what should appear in the UI.
- JSX such as <Button /> creates an element that refers to the Button component.
- React calls the component to obtain the elements it returns.
- Elements are immutable descriptions, while components contain the logic that produces them.
Why interviewers ask this: The interviewer wants you to separate the reusable producer of UI from the element description it produces.
A pure component produces the same JSX for the same props and state without changing outside values during rendering.
- Rendering should calculate UI rather than perform side effects.
- A component must not mutate props or state while it renders.
- Event handlers and effects are the appropriate places for work caused by interaction or synchronization.
Why interviewers ask this: The interviewer checks whether you understand the predictable rendering rule that React components should follow.
Props are inputs that a parent component passes to a child component.
- They can contain strings, numbers, objects, functions, or React elements.
- A child reads props to customize what it renders or how it behaves.
- Data commonly flows downward through the component tree via props.
Why interviewers ask this: A strong answer presents props as general component inputs rather than only HTML-like attributes.
A component should treat props as read-only because their values are owned by its parent.
- Mutating a prop can change shared data without React receiving a clear update request.
- The child should call a provided callback when it needs the parent to make a change.
- New objects or arrays should be created instead of modifying values received through props.
Why interviewers ask this: The interviewer evaluates whether you respect one-way data flow and avoid hidden mutations.
A function component can destructure named props in its parameter list and assign defaults there.
- Destructuring gives direct local names instead of repeated access through a props object.
- A default parameter value is used when the prop is undefined.
- A passed null value does not activate an undefined-only default.
Why interviewers ask this: This checks practical JavaScript knowledge as it applies to clear React component interfaces.
The children prop contains the content placed between a component's opening and closing JSX tags.
- Children can be text, elements, components, expressions, or multiple items.
- Wrapper components can render children inside shared layout or styling.
- The parent controls the nested content while the wrapper controls where it appears.
Why interviewers ask this: The interviewer checks whether you understand React's standard mechanism for nested component content.
Component composition builds larger interfaces by nesting and combining smaller components.
- Parents can configure children through props.
- Wrapper components can accept arbitrary content through children.
- Composition keeps each component focused while allowing the same pieces to be reused in different screens.
Why interviewers ask this: A strong answer explains reuse through combination without introducing inheritance or application architecture.
State is data owned by a component that React preserves between renders and can use to update the UI.
- State represents information that changes over time, such as an input value or selected item.
- Updating state requests another render of the component.
- Each mounted instance of a component has its own local state.
Why interviewers ask this: The interviewer checks whether you connect state to persistent component data and rendering.
Props come from a parent, while state is owned and updated by the component instance that declares it.
- Both props and state can affect the rendered output.
- A component must not modify its props directly.
- State changes through its setter, while a parent changes the props it passes during its own render.
Why interviewers ask this: A strong answer separates ownership and update responsibility while recognizing that both values drive rendering.
A local variable is recreated during each render, and changing it does not ask React to render again.
- React does not preserve ordinary local variables as component state between renders.
- A state setter records a value for the next render and schedules the update.
- Values that should persist and affect visible output usually belong in state.
Why interviewers ask this: The interviewer checks whether you understand both persistence between renders and the need to notify React.
useState returns a pair containing the current state value and a function that updates it.
- Array destructuring commonly gives the pair names such as count and setCount.
- The current value belongs to the render in which the component was called.
- Calling the setter queues a later render with the requested state.
Why interviewers ask this: The interviewer evaluates whether you know the basic useState contract and its relationship to rendering.
React uses the initial useState value when it creates that component's state for the first time.
- Later renders read the stored state rather than resetting it to the initial argument.
- Passing a function lets React call it as an initializer during the initial render.
- The initializer should be pure because React may call it more than once in development checks.
Why interviewers ask this: A strong answer distinguishes state initialization from the value read on every subsequent render.
Locked questions
- 21
What happens when you call a state setter?
- 22
When should you use the functional form of a state update?
forms - 23
How should objects and arrays in state be updated?
- 24
What does it mean that state behaves like a snapshot?
snapshot - 25
When should related values use one state object or separate state variables?
- 26
What is a React Hook?
reacthooks - 27
What are the Rules of Hooks?
hooks - 28
What is useEffect for?
hooks - 29
What does the dependency array of useEffect control?
hooksdependencies - 30
What does an empty dependency array do in useEffect?
hooksdependencies - 31
What happens when useEffect has no dependency array?
hooksdependencies - 32
What is an effect cleanup function?
- 33
How do useEffect and class lifecycle methods relate at a basic level?
hooks - 34
What can trigger a React component to render?
reactcomponents - 35
What is the difference between React's render and commit phases?
react - 36
What is reconciliation in React?
react - 37
When does React preserve a component's state?
reactcomponents - 38
How can a key reset a component's state?
components - 39
Does a parent render always mean the browser DOM for every child changes?
dom - 40
How are events handled in React?
react - 41
Why do you pass an event handler instead of calling it in JSX?
- 42
What is the event object passed to a React event handler?
react - 43
What do preventDefault and stopPropagation do in a React event handler?
react - 44
How do you render a list of items in React?
react - 45
Why does React need keys when rendering lists?
react - 46
Why can an array index be a poor React key?
reactindexes - 47
Can a child component read the key assigned to it?
components - 48
What are the main ways to render content conditionally in React?
react - 49
What is a controlled input in React?
reactforms - 50
What is the difference between controlled and uncontrolled form inputs?
forms - 51
How would you build a reusable product card that supports different products and an optional action button?
- 52
A component receives an array of tasks from an API. How would you render it correctly?
componentsapi - 53
How would you implement loading, error, empty, and success states for a user list?
- 54
How would you make a modal component controllable by its parent?
components - 55
You need primary, secondary, and disabled button styles. How would you design the component?
componentsdesign - 56
How would you implement a selectable list where only one card can be active?
- 57
A click handler calls setCount(count + 1) twice, but the counter increases only once. How would you fix it?
- 58
A form stores firstName, lastName, and fullName in state. How would you simplify it?
forms - 59
A search input and a filtered list are sibling components. Where should the query state live?
componentsqueries - 60
How would you connect an edit form to a live profile preview shown beside it?
forms - 61
A button's function runs during render instead of after a click. What is the likely bug and fix?
- 62
A React form submission reloads the whole page. How would you fix and structure it?
reactforms - 63
Clicking a delete button inside a clickable card also opens the card. How would you fix it?
- 64
How would you implement a controlled email input in React?
reactforms - 65
How would you handle several text fields without writing a separate change handler for each one?
- 66
A checkbox always saves the string value "on" instead of true or false. What should change?
- 67
How would you add client-side validation to a registration form without showing errors too early?
formsvalidation - 68
When should a form be reset after submission, and how would you implement it?
forms - 69
How would you prevent duplicate submissions while an async form request is running?
formsasync - 70
How would you build a file input that shows the selected file name and enforces a size limit?
- 71
How would you fetch a list of posts when a component first mounts using useEffect?
componentshooks - 72
A fetch call returns a 404 response, but the catch block does not run. How would you fix it?
- 73
A component unmounts before its fetch finishes. How would you prevent the obsolete request from affecting the UI?
components - 74
A useEffect fetch runs after every render and creates a loop. How would you debug it?
hooks - 75
A profile should reload whenever userId changes. How would you structure the effect?
- 76
A user quickly switches between two profiles, and the slower first response overwrites the second. How would you fix it?
- 77
How would you avoid sending an API request on every keystroke in a search field?
api - 78
A component adds a window resize listener in useEffect. What must its cleanup do?
componentshooks - 79
A child component rerenders whenever an unrelated parent counter changes. How would you investigate it?
components - 80
A slow list item is wrapped in React.memo but still rerenders because its callback prop changes. How would you address it?
reactcallbacks - 81
A memoized child receives style={{ color: 'red' }} and keeps rerendering. Why, and what would you change?
memoization - 82
A counter in a Next.js App Router page fails because the component uses useState on the server. How would you fix it?
componentshooksnextjs - 83
A text input loses its value whenever a parent toggle changes. What React identity issue would you check?
react - 84
A user object's name is mutated and passed back to setUser, but the screen does not update reliably. How would you fix it?
- 85
A delayed alert always shows an old counter value. How would you decide whether that is a bug and fix it?
alerting - 86
Why does logging state immediately after setName still show the old name, and how would you verify the update?
logging - 87
An effect calculates filteredItems and stores them in state, causing extra renders. How would you improve it?
- 88
When would you use useMemo for a sorted table, and what dependencies should it have?
dependencies - 89
Two components repeat the same fetch, loading, error, and cancellation logic. How would you reuse it?
componentsresilience - 90
Would you put a dropdown's open state in Zustand or local component state?
componentsstate - 91
A page manually fetches the same server data in several components. When would React Query help?
reactcomponentsqueries - 92
How would you implement an optimistic toggle that may fail on the server?
locking - 93
How would you type a React component that accepts a title, optional description, and save callback?
reactcomponentscallbacks - 94
TypeScript rejects a change handler used for both an input and a select. How would you type it safely?
typescript - 95
A Tailwind class built as bg-${color}-500 is missing from production CSS. How would you fix it?
csstailwind - 96
A design shows a clickable card made from a div. How would you implement it accessibly?
design - 97
How would you test a login form with React Testing Library?
reactformsrtl - 98
A test expects fetched data immediately and fails intermittently. How would you repair it?
- 99
How would Storybook help you finish a reusable notification component?
componentsstorybook - 100
You receive a Figma design for a responsive dashboard card. How would you turn it into a React component?
reactcomponentsresponsive