React Viva Preparation: Questions and Answers
A focused set of React viva and lab-exam questions on components, props, state, hooks and the virtual DOM, with short answers you can explain confidently.
QuizMaster TeamSeptember 26, 20268 min read
A React viva usually checks whether you can explain how the library actually works, not whether you have memorised the documentation. This page collects the questions that come up most often in college practicals and lab vivas, answered the way an examiner wants to hear them: short, correct and easy to follow up on.
What React is
- What is React? A JavaScript library for building user interfaces out of reusable components, which describe what the UI should look like for a given state.
- What is JSX? A syntax extension that lets you write HTML-like markup inside JavaScript. It compiles down to regular JavaScript function calls that create React elements.
- What is the virtual DOM? An in-memory representation of the UI that React uses to work out the minimal set of real DOM changes needed after a state update, instead of re-rendering the whole page.
- What is a component? A function (or, historically, a class) that returns markup describing part of the UI, which can be reused with different data.
Props and state
- What is the difference between props and state? Props are inputs passed down from a parent component and are read-only from the child's perspective. State is data a component owns itself and can update, which triggers a re-render when changed.
- Can a child component change its own props? No. Props are immutable from the receiving component's side; if a value needs to change, the parent must pass down a new value, often via a callback the child calls.
- What does `useState` return? An array with two items: the current state value and a function to update it, typically destructured as
const [value, setValue] = useState(initial). - Why should you not mutate state directly? React detects changes by reference. Mutating an array or object in place does not create a new reference, so React may not notice the change and re-render.
Hooks
- What is a hook? A function (starting with
use) that lets a function component use React features like state and lifecycle behaviour, which were previously only available in class components. - What is `useEffect` for? Running code that synchronises with something outside React, such as a subscription, a timer or fetching data, after the component renders.
- What does the dependency array in `useEffect` control? Which values the effect depends on. React re-runs the effect when any listed value changes since the last render; an empty array means it runs once after the first render.
- What are the rules of hooks? Hooks must be called at the top level of a component (not inside loops, conditions or nested functions) and only from React function components or other hooks.
Rendering and lists
- Why does a list need a `key` prop? So React can track which item is which across re-renders, letting it correctly reorder, insert or remove elements without losing their state.
- What happens if you use the array index as a key? It works until the list is reordered, filtered or has items inserted/removed, at which point item identity and state can attach to the wrong row.
- What triggers a component to re-render? A change to its own state, a change to the props it receives from its parent, or a change to any context value it consumes.
Forms and events
- What is a controlled component? An input whose value is driven by React state, updated via an
onChangehandler, so React is always the single source of truth for what is displayed. - How do you prevent a form's default submit behaviour? Call
event.preventDefault()inside the form'sonSubmithandler.
How to prepare
- Be ready to explain the difference between props and state with a one-line example of each.
- Sketch a small component on paper and describe what re-renders it and why.
- Practise with the React Core Concepts quiz and the React Hooks quiz.
- Review React props vs state and the React Hooks mental model for deeper explanations behind these answers.
Key takeaways
- Know props versus state cold, and be ready to give an example of each.
- Explain useEffect as synchronising with something outside React, not as a general-purpose "run some code" hook.
- Understand why stable, unique keys matter for lists.
- Practise explaining concepts out loud, with a tiny code example, not just reciting definitions.