INT252 viva questions Web App Development With Reactjs
50 questions across 6 units, with answers. Say your answer out loud first, then check it.
-
Question 1 of 50Unit I, Refreshing JavaScriptEasy
In the context of rendering lists in React, why do we prefer using the .map() array method over .forEach()?
Answer
.map() returns a new array, which allows React to transform data directly into a list of JSX elements. .forEach() only iterates and returns undefined, so it cannot be used directly inside a JSX expression to render content.
-
Question 2 of 50Unit I, ReactJS Installation & JSXIntermediate
If I write a standard HTML 'class' attribute inside JSX, React throws a warning. Why does this happen, and what is the underlying technical reason regarding JavaScript?
Answer
In JSX, you must use 'className' instead of 'class'. This is because JSX is syntactic sugar for JavaScript, and 'class' is a reserved keyword in JavaScript (used for defining classes). Using it would confuse the transpiler.
-
Question 3 of 50Unit I, ES6 RefresherIntermediate
Scenario: You have a state object with user details. You want to update only the email address while keeping the rest of the properties intact. Which ES6 operator would you use and how?
Answer
I would use the Spread Operator (...). I would return a new object, spreading the existing state first, and then overriding the specific property, like: { ...state, email: 'new@email.com' }.
-
Question 4 of 50Unit II, React Virtual DOMHard
Explain the concept of 'Reconciliation' in React. How does the Virtual DOM minimize performance costs compared to the real DOM?
Answer
Reconciliation is the process where React updates the DOM. When state changes, React creates a new Virtual DOM tree and compares it to the previous one (diffing). It calculates the minimum number of changes required and strictly updates only those specific nodes in the real DOM, rather than re-painting the entire page.
-
Question 5 of 50Unit II, Components and styles in ReactEasy
What is the primary difference in scope between standard CSS stylesheets and CSS Modules in React?
Answer
Standard CSS stylesheets have global scope, meaning class names can clash across different components. CSS Modules are scoped locally to the component; React generates unique class names during the build to ensure styles don't leak or conflict.
-
-
Question 6 of 50Unit II, Components (Functional vs Class)Intermediate
Before Hooks were introduced, what was a major limitation of Functional Components compared to Class Components?
Answer
Before Hooks, Functional Components were 'stateless' and could not hold their own local state or access lifecycle methods (like componentDidMount). They were primarily used just for presentation (dumb components).
-
Question 7 of 50Unit III, Understanding HooksIntermediate
If I put a console.log immediately after a setFunction in useState (e.g., setCount(5); console.log(count)), I usually see the old value. Why?
Answer
State updates in React are asynchronous. When you call the setter function, React schedules a re-render, but the current closure still holds the old value. The new value will only be available in the next render cycle or inside a useEffect that watches that variable.
-
Question 8 of 50Unit III, Understanding HooksHard
Compare useMemo and useCallback. In what specific scenario would you choose useCallback over useMemo?
Answer
useMemo caches the result of a function calculation. useCallback caches the function definition itself. You choose useCallback when you pass a function as a prop to a child component (wrapped in React.memo) to prevent the child from re-rendering unnecessarily due to a new function reference being created on every parent render.
-
Question 9 of 50Unit III, Component LifecycleIntermediate
In a Class Component, we use componentWillUnmount to clean up resources. How do we achieve this exact same behavior using the useEffect hook?
Answer
We achieve this by returning a cleanup function from inside the useEffect callback. If the dependency array is empty, this return function runs only when the component unmounts.
-
Question 10 of 50Unit III, Understanding HooksIntermediate
What happens if you use the useRef hook to store a value and then change that value? Does it trigger a re-render?
Answer
No, updating a useRef value (ref.current) does not trigger a re-render. It is used to persist data across renders without causing the visual update cycle that useState triggers.
-
Question 11 of 50Unit III, EventsEasy
In React, event handlers are often named in camelCase (e.g., onClick). Is this the same as the native DOM onclick event?
Answer
No, it is not identical. React uses a 'SyntheticEvent' system. It wraps the browser's native event to ensure cross-browser compatibility and performance optimization, though the API interface looks very similar.
-
Question 12 of 50Unit IV, Working with FormsIntermediate
Explain the difference between a 'Controlled' and an 'Uncontrolled' component in the context of React forms.
Answer
In a Controlled component, the form data is handled by React state (the input value is tied to state). In an Uncontrolled component, the form data is handled by the DOM itself, usually accessed via a Ref.
-
Question 13 of 50Unit IV, Handling formsEasy
When submitting a form in React, we almost always call e.preventDefault() as the first line in the handler. Why?
Answer
To prevent the browser's default behavior, which is to reload the full page. Since we are building Single Page Applications (SPAs), we want to handle the data submission via JavaScript without a page refresh.
-
Question 14 of 50Unit V, RoutingIntermediate
Why should we use the <Link> component from React Router instead of a standard HTML <a> tag for navigation?
Answer
The HTML <a> tag causes a full page refresh, reloading all CSS and JS bundles. The <Link> component utilizes the History API to change the URL and render the new component view without reloading the page, maintaining the SPA experience.
-
Question 15 of 50Unit V, HTTP MethodsIntermediate
Compare Axios and Fetch. Since Fetch is built into the browser, why does the syllabus include Axios? What is one convenience Axios offers?
Answer
Axios offers better developer ergonomics. For example, Axios automatically transforms JSON data (so you don't need to call .json()), handles error status codes (like 404 or 500) inside the .catch() block automatically (unlike Fetch), and has built-in support for request interception.
-
Question 16 of 50Unit V, RoutingHard
Scenario: You need to pass a specific Product ID from a list page to a details page via the URL. How do you define this in the Route, and how do you access it in the destination component?
Answer
I would define the route path with a dynamic segment, like '/product/:id'. In the destination component, I would use the useParams hook (from react-router-dom) to extract the 'id' value from the URL.
-
Question 17 of 50Unit VI, ReduxHard
In Redux, reducers must be 'pure functions'. If I need to update an array in the Redux store, why is it wrong to use .push()?
Answer
.push() mutates the original array. Redux relies on shallow equality checking (reference checks) to determine if state has changed. If you mutate the array directly, Redux won't detect the change and components won't re-render. You must return a new array copy.
-
Question 18 of 50Unit VI, ReduxIntermediate
Briefly explain the 'Unidirectional Data Flow' in Redux.
Answer
The flow is strictly one-way: An Action is Dispatched from a component -> The Reducer handles the action and updates the Store -> The Store passes the new State back down to the Component.
-
Question 19 of 50Unit VI, Debugging and DeploymentEasy
When you run the command 'npm run build', what is being generated in the 'build' or 'dist' folder?
Answer
It generates a production-ready version of the app. This includes minified JavaScript files, optimized CSS, and an index.html file. The code is transpiled and bundled so it can be deployed to a static server.
-
Question 20 of 50Unit VI, Debugging the React AppIntermediate
Code Defense: You see a warning in the console saying 'Each child in a list should have a unique key prop'. Why shouldn't you just use the array index as the key?
Answer
Using the array index is risky if the list can be reordered, filtered, or items can be inserted at the top. It can confuse React's reconciliation process, leading to incorrect DOM updates or bugs with component state (like input fields preserving wrong values).
-
Question 21 of 50Unit I, Refreshing JavaScriptEasy
What is the specific advantage of using the 'Arrow Function' syntax when passing a callback to an event handler in a Class Component?
Answer
Arrow functions do not have their own 'this' context; they inherit it from the parent scope. This often eliminates the need to manually bind the function in the constructor.
-
Question 22 of 50Unit I, Refreshing JavaScriptIntermediate
Explain 'Object Destructuring' in the context of receiving Props. Why do developers prefer
({ name, age })over(props)in the function signature?Answer
Destructuring allows you to unpack values from the props object directly into distinct variables. It makes the code cleaner and makes it immediately obvious which properties the component relies on without repeating 'props.name' or 'props.age'.
-
Question 23 of 50Unit I, ReactJS InstallationEasy
When you look at the folder structure created by Vite or Create React App, what is the purpose of the 'public' folder versus the 'src' folder?
Answer
The 'src' folder contains the source code (components, logic, styles) that will be processed and bundled by the build tool. The 'public' folder contains static assets (like index.html, favicon, robots.txt) that are served directly without processing.
-
Question 24 of 50Unit I, JSX ExpressionsIntermediate
Can I use an
if-elsestatement directly inside a JSX expression (inside the curly braces)? Why or why not?Answer
No, you cannot. JSX expressions accept JavaScript expressions (which evaluate to a value), but
if-elseis a statement. You must use the ternary operator (condition ? true : false) or logical AND (&&) instead. -
Question 25 of 50Unit II, Components and stylesEasy
What is the 'children' prop in React, and how is it different from a standard prop like 'title'?
Answer
The 'children' prop is a special prop that automatically passes whatever content is nested between the opening and closing tags of a component. It allows for component composition, whereas standard props are passed as attributes.
-
Question 26 of 50Unit II, CSS in ReactIntermediate
When using Inline Styling in React, why do we write
backgroundColorinstead of the standard CSSbackground-color?Answer
In React, inline styles are passed as JavaScript objects, not strings. JavaScript property names cannot contain hyphens (unless quoted), so React uses camelCase for CSS properties.
-
Question 27 of 50Unit II, PropsIntermediate
React enforces 'Unidirectional Data Flow'. If a child component needs to communicate with a parent component, how is this achieved using Props?
Answer
The parent passes a function (a callback) down to the child via props. The child then calls this function, optionally passing data as arguments, effectively sending data 'up' to the parent.
-
Question 28 of 50Unit II, ComponentsHard
Code Defense: I have a Functional Component that calculates a heavy mathematical value on every render, causing lag. Which specific Hook should I use to fix this and how?
Answer
You should use
useMemo. By wrapping the heavy calculation in useMemo and providing a dependency array, the calculation will only re-run when the dependencies change, rather than on every single render. -
Question 29 of 50Unit III, Understanding HooksEasy
What is the first rule of Hooks regarding where they can be called inside a component?
Answer
Hooks must only be called at the top level of the React function. They cannot be called inside loops, conditions (if-statements), or nested functions, to ensure they run in the exact same order on every render.
-
Question 30 of 50Unit III, useContextIntermediate
Scenario: You have a 'Theme' (Light/Dark) that needs to be accessed by a button nested 5 levels deep. Why is
useContextbetter than passing props here?Answer
Passing props through 5 levels of components that don't need the data themselves is called 'Prop Drilling' and makes code hard to maintain.
useContextallows the button to access the Theme value directly from the Provider, bypassing the intermediate components. -
Question 31 of 50Unit III, Component LifecycleIntermediate
Which lifecycle phase is associated with the
useEffecthook when the dependency array is missing entirely (not empty, but omitted)?Answer
It corresponds to the 'Updation' phase (and Mounting). Without a dependency array, the effect runs after every single render of the component.
-
Question 32 of 50Unit III, useReducerHard
When would you prefer
useReduceroveruseStatefor managing local component state?Answer
I would use
useReducerwhen the state logic is complex (e.g., involves multiple sub-values) or when the next state depends on the previous state in a complicated way. It helps organize state transitions using specific actions (like 'INCREMENT', 'RESET'). -
Question 33 of 50Unit III, Custom HooksIntermediate
What is a 'Custom Hook' technically? Does it share state between the components that use it?
Answer
Technically, a custom hook is just a JavaScript function that starts with 'use' and calls other hooks. No, it does not share state. It shares stateful logic. Each component that calls the custom hook gets its own isolated state instance.
-
Question 34 of 50Unit IV, Forms validationEasy
In a controlled form, what prop must be set on the
<input>element to ensure React controls the data?Answer
The
valueprop must be set to the state variable, and theonChangeprop must be set to a handler that updates that state. -
Question 35 of 50Unit IV, Handling formsIntermediate
Scenario: You have a form with 10 input fields. Instead of creating 10 separate
handleNameChange,handleEmailChange, etc., functions, how can you write one generic change handler?Answer
You can add a
nameattribute to each input. Inside the handler, you accesse.target.nameand use Computed Property Names (ES6) to update the state:setState({ ...state, [e.target.name]: e.target.value }). -
Question 36 of 50Unit IV, FormsHard
What happens if you pass the value
undefinedornullto a controlled input'svalueprop initially, and then later update it to a string?Answer
React will verify it as switching from an 'uncontrolled' to a 'controlled' component and will throw a warning in the console. You should always initialize state with an empty string
''rather than null/undefined for inputs. -
Question 37 of 50Unit V, HTTP MethodsEasy
In the context of a CRUD application, which HTTP method is typically used to update an existing resource, and which is used to create a new one?
Answer
POST is typically used to Create a new resource. PUT (or PATCH) is used to Update an existing resource.
-
Question 38 of 50Unit V, RoutingIntermediate
What is the difference between
useParamsanduseSearchParams(or query parameters)?Answer
useParamsis used to get dynamic segments defined in the route path (like/users/:id).useSearchParamsis used to read data from the query string after the '?' (like/search?q=react), which is not part of the route definition. -
Question 39 of 50Unit V, Fetching dataIntermediate
If you perform a
fetchcall inside auseEffect, why is it important to use a dependency array[]?Answer
If you omit the array, the component will fetch data, update state, trigger a re-render, runs the effect again, fetch data again, and create an infinite loop that crashes the browser or spams the API.
-
Question 40 of 50Unit V, RoutingEasy
In React Router, what does the
<Outlet />component do?Answer
The
<Outlet />component is used in parent route components to render their child route elements. It acts as a placeholder for where the child content should appear. -
Question 41 of 50Unit V, HTTP MethodsHard
When using
fetch(), if the server returns a 404 error, does the code enter the.catch()block? Why or why not?Answer
No, it does not.
fetchonly rejects the promise (enters .catch) on network failures (like DNS issues). A 404 is a valid HTTP response, so it enters.then(). You must manually checkresponse.okto handle HTTP errors. -
Question 42 of 50Unit VI, ReduxEasy
What is a 'Store' in Redux?
Answer
The Store is an object that holds the entire application's state tree. It is the single source of truth for the data in a Redux app.
-
Question 43 of 50Unit VI, ReduxIntermediate
Explain the role of an 'Action' in Redux. What two properties does it typically have?
Answer
An Action is a plain JavaScript object that describes what happened in the application. It typically has a
typeproperty (a string constant describing the event) and an optionalpayloadproperty (containing data needed for the update). -
Question 44 of 50Unit VI, Connecting Components (Redux)Intermediate
In modern Redux (Hooks), which hook is used to read data from the store, and which hook is used to trigger state changes?
Answer
useSelectoris used to read data (subscribe) from the store.useDispatchis used to get the dispatch function to trigger actions. -
Question 45 of 50Unit VI, ReduxHard
Why can't we perform asynchronous operations (like API calls) directly inside a Redux Reducer?
Answer
Reducers must be pure, synchronous functions. They take the old state and an action, and return new state immediately. Performing async logic (side effects) would break the predictable state flow. Async logic belongs in middleware (like Thunks) or the component.
-
Question 46 of 50Unit VI, DebuggingEasy
What is the specific browser extension recommended for inspecting the Component hierarchy and Props in a React app?
Answer
React Developer Tools (or simply React DevTools).
-
Question 47 of 50Unit VI, DeploymentIntermediate
Why do we set an environment variable like
NODE_ENVto 'production' before deploying?Answer
This signals to libraries (including React) to enable optimizations. It removes development-only warnings, checks, and code blocks, making the application smaller and faster.
-
Question 48 of 50Unit III, State vs PropsEasy
In one sentence, what is the key difference between State and Props regarding ownership?
Answer
State is managed internally by the component itself (private), whereas Props are passed externally from a parent component (read-only).
-
Question 49 of 50Unit I, ES6 RefresherEasy
What does the .filter() array method return?
Answer
It returns a new array containing only the elements that passed the test condition defined in the callback function.
-
Question 50 of 50Unit III, EventsIntermediate
If I want to access the underlying DOM element inside a functional component to set focus manually, which Hook should I use?
Answer
You should use the
useRefhook, assign it to therefattribute of the element, and access the element viaref.current.
That's the set
Go back over the ones you couldn't answer without looking. The unit notes cover each topic in full.
Nearly through. Did viva questions for INT252 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did viva questions for INT252 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill; the rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks.