React Interview Questions for Freshers
12 React interview questions for freshers and students (0 to 1 year): JSX, props, useState, conditional rendering, controlled inputs, effects and Fragments. Each answer explains why the other options are wrong.
CoversEffectsFormsHooksJsxPropsReactRenderingStateStyling
By Deepak KumarPublished Answers checked by Deepak
Take it as a timed test
- 12 questions
- 15 min
- Pass mark 60%
- Answers shown at the end
No sign-up. Your answers and scores stay in this browser.
This freshers paper has 12 React questions for freshers and students with roughly 0 to 1 year of experience. It covers JSX, props, useState, conditional rendering, controlled inputs, effects and Fragments. Ten questions are on this page with full explanations; the timed test also includes two questions that aren't shown here, so practise for understanding rather than memory.
How should you use this paper?
Answer each practice question before opening its explanation, and say your reasoning out loud the way you would in an interview. Then take the timed test: 15 minutes, a pass mark of 60%, with answers shown at the end. Your report breaks your score down by topic and difficulty, and you can retry only the questions you missed.
Practice questions with answers
Try each one before opening the answer. The explanation covers why the other options are wrong. The timed test also uses 2 questions that aren't shown here, so practise for understanding, not memory.
What is JSX?
Show answer and explanation
Answer: A. A syntax that looks like HTML and is compiled into JavaScript function calls that create React elements
JSX is syntax sugar. A compiler such as Babel, SWC or esbuild turns <h1 className="t">Hi</h1> into a call like jsx('h1', { className: 't', children: 'Hi' }), which returns a plain object describing the UI. That's why attributes use JavaScript names like className and htmlFor, and why you can embed any expression inside { }.
Can a child component change the props it receives?
Show answer and explanation
Answer: A. No: props are read-only; the parent changes them, or passes a callback the child can call
Props flow one way, from parent to child, and React treats them as read-only. To change something the parent owns, the parent passes a function such as onChange, and the child calls it; the parent updates its state and re-renders with new props. Mutating a prop object directly leads to UI that doesn't update and bugs that are hard to trace.
Calling a useState setter with an object merges it into the old state object, like class components' setState.
TrueFalse
Show answer and explanation
Answer: False
False. The useState setter replaces the value completely. If state is { name, email } and you call setUser({ name: 'Ana' }), the email is gone. Spread the old value in yourself: setUser(u => ({ ...u, name: 'Ana' })). Or keep unrelated values in separate useState calls, or use useReducer for complex objects.
With const count = 0, what does <div>{count && <p>Items</p>}</div> render?
const count = 0;
return <div>{count && <p>Items</p>}</div>;Show answer and explanation
Answer: A. A div containing the text "0"
&& returns its left side when that side is falsy, so the expression evaluates to 0. React doesn't render false, null or undefined, but it does render numbers, so a stray 0 appears on the page. Make the condition a real boolean: {count > 0 && ...}, or use a ternary.
What makes an input a controlled component?
Show answer and explanation
Answer: A. Its value comes from state and every change goes through an onChange handler that updates that state
In a controlled input, React state is the single source of truth: value={name} plus onChange={e => setName(e.target.value)}. That makes validation, formatting and resetting easy. An uncontrolled input keeps its own value in the DOM, set initially with defaultValue and read with a ref or FormData, which is simpler for basic forms.
When does useEffect(fn, []) run?
Show answer and explanation
Answer: A. After the first render is shown on screen; in development with StrictMode, React runs it, cleans up, and runs it again once
An empty dependency array means the effect has nothing to re-sync on, so it runs once after the component mounts and its cleanup runs on unmount. In development, StrictMode deliberately mounts, unmounts and remounts each component once to surface effects without proper cleanup, so you'll see it run twice there but only once in production.
Which of these are valid ways to style a React element? Select all that apply.
Show answer and explanation
Answer: A. className="card" + B. style={{ color: 'red' }} + C. A CSS Module: className={styles.card}
React uses className because class is a reserved word in JavaScript. The style prop takes an object with camelCase properties, such as { backgroundColor: 'red' }, not a CSS string; passing a string throws an error. CSS Modules scope class names to the component, and frameworks like Tailwind also just set className.
Two sibling components need to show and change the same value. What is the standard approach?
Show answer and explanation
Answer: A. Lift the state up to their closest common parent and pass it down as props
React data flows down, so shared state belongs in the nearest component above both siblings. The parent holds it with useState and passes the value and an updater function to each child. Copying state into two places and syncing with effects causes extra renders and bugs. For values needed far down the tree, context avoids passing props through many levels.
Match each React hook to when you'd reach for it.
- useState
- useEffect
- useRef
- useContext
- Syncing with something outside React, like a subscription
- Reading a value provided higher up the tree
- A value that changes and should update the screen
- A reference to a DOM element, such as to focus an input
Show answer and explanation
Answer: useState → A value that changes and should update the screenuseEffect → Syncing with something outside React, like a subscriptionuseRef → A reference to a DOM element, such as to focus an inputuseContext → Reading a value provided higher up the tree
useState holds render-affecting data. useEffect is for side effects that sync with the outside world: subscriptions, timers, imperative widgets. It isn't for deriving values from props, which you can compute during render. useRef holds a mutable value or DOM node without re-rendering, and useContext reads from the nearest provider.
Why use <>...</> (a Fragment)?
Show answer and explanation
Answer: A. To return several elements from a component without adding an extra DOM element
A component must return a single node, and wrapping siblings in a div adds markup that can break layouts, such as table rows or flex children. A Fragment groups them without adding anything to the DOM. Use the long form <Fragment key={id}> when you need a key, for example when mapping a list to pairs of elements.
Answered them all? Take the same questions against the clock and get a topic-by-topic report.
Start the timed test