Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
The input event contains the new text at event.target.value, which should be passed to the state setter.
Question 38 of 60 · Re-render triggers and optimization awareness · Medium
A child component receives an inline object prop from its parent on every render. Why can this affect a memoized child?
Not quite. Try another option.
Answer: The object reference may differ each render
A newly created object has a new reference, so shallow prop comparison may treat it as changed even when its contents are equal.
Question 39 of 60 · State management best practices · Medium
Why should state updates avoid directly mutating an existing array?
Not quite. Try another option.
Answer: React may not detect the same array reference
Creating a new array with operations such as spread or filter gives React a changed reference and preserves predictable state updates.
Question 40 of 60 · Managing side effects using useEffect · Medium
A fetch request starts in an effect and may finish after unmounting. What is an appropriate concern to address?
Not quite. Try another option.
Answer: Ignoring or aborting stale requests
Cleanup can abort a request or mark its result as stale, preventing outdated asynchronous work from updating the component.
Question 41 of 60 · Event handling mechanisms in React · Hard
A button is rendered inside a form using <button onClick={handleSave}>Save</button>. The handleSave function calls an asynchronous API and then updates state. Which change best prevents an unintended form submission while preserving React's event handling?
preventDefault() cancels the browser's default form-submission behavior. stopPropagation() only affects event propagation and does not prevent the default action.
Question 42 of 60 · Local state management using useState · Hard
Consider const [user, setUser] = useState({ name: "Ava", age: 20 });. Which update correctly changes only age while preserving the other properties?
Not quite. Try another option.
Answer: setUser({ ...user, age: 21 })
Objects in state are replaced rather than automatically merged. Spreading the previous object preserves name while replacing age.
Question 43 of 60 · State update behavior and batching · Hard
Inside one React event handler, the component executes setCount(count + 1); setCount(count + 1);. If count is initially 0, what value will normally be rendered after the handler completes?
Not quite. Try another option.
Answer: 1, because both updates read the same snapshot
Both expressions calculate 1 from the same render snapshot. React batches the updates, and the later replacement value remains 1.
Question 44 of 60 · State update behavior and batching · Hard
A click handler runs setCount(c => c + 1); setCount(c => c + 1);. What is the resulting value if the initial state is 0?
Not quite. Try another option.
Answer: 2, because updater functions compose sequentially
Functional updaters receive the latest pending state. React applies the first updater to produce 1, then the second to produce 2, even when batching occurs.
Question 45 of 60 · Re-render triggers and optimization awareness · Hard
A parent component re-renders because its local state changed. A memoized child receives a primitive prop whose value is unchanged. Under normal React behavior, what is the most accurate result?
Not quite. Try another option.
Answer: The child skips rendering when its props compare equal
React.memo can skip a child render when its incoming props are shallowly equal. Primitive values with unchanged values compare equal, independent of the parent's render.
Question 46 of 60 · Re-render triggers and optimization awareness · Hard
A component contains const data = { enabled: true }; and passes data to a child wrapped in React.memo. The parent re-renders for unrelated reasons. Why can the child still re-render?
Not quite. Try another option.
Answer: A new object reference is created each render
The object literal creates a new reference on every parent render. Shallow comparison sees the prop as changed even though its contents are identical.
Question 47 of 60 · Derived state concepts · Hard
A component stores items and also stores filteredItems, which is recalculated whenever a search term changes. What is generally the best design when filtering is inexpensive and deterministic?
Not quite. Try another option.
Answer: Store items and searchTerm, then derive the filtered list during render
Inexpensive deterministic values should usually be derived from source state during render. This avoids synchronization bugs and eliminates redundant state.
Question 48 of 60 · State management best practices · Hard
Which state structure best represents a form with fields email and password when updates may arrive independently?
Not quite. Try another option.
Answer: Two state variables or one object updated with functional merging
Independent fields should remain independently addressable. Separate state variables or a consistently merged object preserve unrelated values during updates.
Question 49 of 60 · Built-in hooks including useState, useEffect, and useContext · Hard
A component reads theme with useContext(ThemeContext) and also calls useState and useEffect. Which statement is correct when the provider value changes?
Not quite. Try another option.
Answer: Consumers can re-render when the context value changes
A context consumer subscribes to its context. When the provider supplies a changed value, React may re-render that consumer so it can observe the new value.
Question 50 of 60 · Managing side effects using useEffect · Hard
A component fetches data in useEffect(() => { fetchData(id); }, [id]). What is the primary reason the fetch belongs in an effect rather than directly in the component body?
Not quite. Try another option.
Answer: Effects separate external synchronization from pure rendering
Fetching is an interaction with an external system. useEffect runs that synchronization after rendering instead of repeating it as part of every render calculation.
Question 51 of 60 · Managing side effects using useEffect · Hard
A search component starts a request whenever query changes. An older request may finish after a newer one. Which approach best prevents stale results from overwriting current results?
Not quite. Try another option.
Answer: Use a cleanup function with AbortController or an active flag
Cleanup can abort the previous request or mark it inactive. The completion handler can then avoid applying results that no longer correspond to the current query.
Question 52 of 60 · Dependency array semantics and effect cleanup · Hard
What is the semantic difference between useEffect(effect) and useEffect(effect, []) in a component that mounts once and later re-renders?
Not quite. Try another option.
Answer: The first runs after every render; the second runs after mount
With no dependency array, the effect runs after every committed render. An empty array means it runs after the initial mount, with cleanup occurring on unmount.
Question 53 of 60 · Dependency array semantics and effect cleanup · Hard
An effect subscribes to a socket using roomId but declares useEffect(() => subscribe(roomId), []). What is the key defect?
Not quite. Try another option.
Answer: The subscription can remain tied to the initial room
The effect captures the initial roomId and will not resubscribe when it changes. The dependency array should include values used by the effect, including roomId.
Question 54 of 60 · Dependency array semantics and effect cleanup · Hard
Which cleanup behavior is correct for useEffect(() => { const id = setInterval(tick, 1000); return () => clearInterval(id); }, [])?
Not quite. Try another option.
Answer: Cleanup runs when the component unmounts
With an empty dependency array, the effect setup runs after mount and its cleanup runs on unmount. The cleanup also runs before a future effect replacement, if dependencies were present.
Question 55 of 60 · Performance optimization using useCallback and useMemo · Hard
A memoized child receives a callback from its parent. The callback does not need to change unless userId changes. Which implementation most directly supports child memoization?
Not quite. Try another option.
Answer: Create the callback with useCallback(() => loadUser(userId), [userId])
useCallback preserves the function reference until userId changes. This can allow a memoized child to skip renders caused only by callback identity changes.
Question 56 of 60 · Performance optimization using useCallback and useMemo · Hard
A component computes an expensive sorted list from items and sortOrder. Which use of useMemo is correct?
useMemo receives a calculation function and dependencies that determine its result. The sorted value must be recomputed when either items or sortOrder changes.
Question 57 of 60 · Introduction to custom hooks for logic reuse · Hard
A custom hook useOnlineStatus subscribes to a browser online-status event. Which property is essential for making the hook reusable across multiple components?
Not quite. Try another option.
Answer: It must encapsulate setup and cleanup while exposing state or actions
A custom hook reuses stateful logic, including effect setup and cleanup. Components consume its returned data or actions without duplicating subscription details.
Question 58 of 60 · Rules of hooks · Hard
Which component correctly follows the Rules of Hooks when a feature is enabled conditionally?
Not quite. Try another option.
Answer: Call the hook unconditionally and branch inside its effect or logic
Hooks must be called in the same order on every render. Conditional behavior belongs inside the hook callback or surrounding logic, not around the hook call.
Question 59 of 60 · Common pitfalls and anti-patterns · Hard
An effect contains setTotal(price * quantity) and declares [price, quantity, total] as dependencies. What problem can this create?
Not quite. Try another option.
Answer: The state update can cause a redundant render cycle
Because the effect updates total and depends on total, it runs again after that update. React may bail out when the value is equal, but the dependency is unnecessary for this derived value.
Question 60 of 60 · Common pitfalls and anti-patterns · Hard
A component uses useEffect(() => { document.title = title; }, []), where title is a prop that can change. What is the most accurate correction?
Not quite. Try another option.
Answer: Add title to the dependency array
The effect reads title, so it must react when that value changes. Using [title] prevents the document title from becoming stale.
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of INT252 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 of 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.