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.

Unit 3 MCQs State, Events, Hooks, and Side Effects

INT252 — Web App Development With Reactjs 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Event handling mechanisms in React Easy

    Which prop is commonly used to handle a button click in React?

  2. Question 2 of 60 Event handling mechanisms in React Easy

    How should a function named handleClick normally be assigned as a React click handler?

  3. Question 3 of 60 Local state management using useState Easy

    What does the useState hook return?

  4. Question 4 of 60 Local state management using useState Easy

    Which code correctly creates a state variable named count with an initial value of 0?

  5. Question 5 of 60 State update behavior and batching Easy

    What does React batching do with multiple state updates in the same event handler?

  6. Question 6 of 60 State update behavior and batching Easy

    Which update is preferred when the next count depends on its previous value?

  7. Question 7 of 60 Re-render triggers and optimization awareness Easy

    Which action normally triggers a React component to re-render?

  8. Question 8 of 60 Derived state concepts Easy

    What is derived state?

  9. Question 9 of 60 State management best practices Easy

    How should an array stored in React state usually be updated?

  10. Question 10 of 60 Built-in hooks including useState, useEffect, and useContext Easy

    Which built-in hook reads a value from a React context?

  11. Question 11 of 60 Managing side effects using useEffect Easy

    Which task is a typical side effect handled with useEffect?

  12. Question 12 of 60 Managing side effects using useEffect Easy

    When does a useEffect callback normally run?

  13. Question 13 of 60 Dependency array semantics and effect cleanup Easy

    What happens when useEffect is used without a dependency array?

  14. Question 14 of 60 Dependency array semantics and effect cleanup Easy

    What does [count] mean in useEffect(() => { ... }, [count])?

  15. Question 15 of 60 Dependency array semantics and effect cleanup Easy

    How does an effect provide a cleanup operation?

  16. Question 16 of 60 Performance optimization using useCallback and useMemo Easy

    What does useCallback memoize?

  17. Question 17 of 60 Performance optimization using useCallback and useMemo Easy

    What does useMemo commonly memoize?

  18. Question 18 of 60 Introduction to custom hooks for logic reuse Easy

    What is the main purpose of a custom hook?

  19. Question 19 of 60 Rules of hooks Easy

    Where should hooks be called in a React function component?

  20. Question 20 of 60 Common pitfalls and anti-patterns Easy

    Which action is a common React state anti-pattern?

  21. Question 21 of 60 Event handling mechanisms in React Medium

    Which event handler correctly passes an item identifier to a React function component when the button is clicked?

  22. Question 22 of 60 Local state management using useState Medium

    What is the best way to update a counter when the new value depends on the previous value?

  23. Question 23 of 60 State update behavior and batching Medium

    Given setCount(count + 1); setCount(count + 1); inside one event handler, what usually happens when count is initially 0?

  24. Question 24 of 60 Re-render triggers and optimization awareness Medium

    Which change normally causes a function component to render again?

  25. Question 25 of 60 Derived state concepts Medium

    A component receives price and quantity as props and displays their product. Which approach is generally preferred?

  26. Question 26 of 60 State management best practices Medium

    A form has several related fields that must be updated together based on the previous form state. Which approach is most appropriate?

  27. Question 27 of 60 Built-in hooks including useState, useEffect, and useContext Medium

    Which hook is most suitable for reading a theme value supplied by a React context?

  28. Question 28 of 60 Managing side effects using useEffect Medium

    A component must subscribe to a browser event when it mounts. Which pattern is most appropriate?

  29. Question 29 of 60 Dependency array semantics and effect cleanup Medium

    What does an effect with dependency array [userId] do when userId changes?

  30. Question 30 of 60 Dependency array semantics and effect cleanup Medium

    Which cleanup is needed for an interval created inside an effect?

  31. Question 31 of 60 Performance optimization using useCallback and useMemo Medium

    When is useMemo most useful in a component?

  32. Question 32 of 60 Performance optimization using useCallback and useMemo Medium

    Why might a parent component use useCallback when passing a function to a memoized child?

  33. Question 33 of 60 Introduction to custom hooks for logic reuse Medium

    What is the main purpose of a custom hook such as useWindowWidth?

  34. Question 34 of 60 Rules of hooks Medium

    Which example follows the Rules of Hooks?

  35. Question 35 of 60 Common pitfalls and anti-patterns Medium

    What is a common problem with using an effect to calculate a value that can be computed from props during rendering?

  36. Question 36 of 60 State update behavior and batching Medium

    Which code correctly increments a counter three times within one handler?

  37. Question 37 of 60 Event handling mechanisms in React Medium

    A controlled input uses value={name}. Which handler correctly updates its value?

  38. 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?

  39. Question 39 of 60 State management best practices Medium

    Why should state updates avoid directly mutating an existing array?

  40. 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?

  41. 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?

  42. 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?

  43. 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?

  44. 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?

  45. 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?

  46. 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?

  47. 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?

  48. 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?

  49. 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?

  50. 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?

  51. 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?

  52. 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?

  53. 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?

  54. 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); }, [])?

  55. 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?

  56. 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?

  57. 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?

  58. Question 58 of 60 Rules of hooks Hard

    Which component correctly follows the Rules of Hooks when a feature is enabled conditionally?

  59. 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?

  60. 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?

That's unit 3

Answer a few questions and your score shows up here.