Unit 3: State, Events, Hooks, and Side Effects - Subjective Questions

INT252 — Web App Development With Reactjs • Practice Questions with Detailed Answers

20 questions

1

Explain the event handling mechanism in React. How does it differ from event handling in traditional HTML?

2

Describe how arguments can be passed to React event handlers. Also explain the purpose of the event object.

3

Define local state in React and explain how the useState hook is used to manage it.

4

Explain functional state updates in React. Why are they important when the next state depends on the previous state?

5

Discuss React's state update behavior and batching. Illustrate your answer with an appropriate example.

6

What causes a React component to re-render? Explain the major re-render triggers and their relationship with child components.

7

Explain how objects and arrays should be updated when they are stored in React state. Why is direct mutation considered an anti-pattern?

8

Define derived state. Distinguish between computing a derived value during rendering and storing that value as separate state.

9

Describe important best practices for managing state in React applications.

10

What is the useEffect hook? Explain why side effects should be separated from the rendering process.

11

Compare the behavior of useEffect with no dependency array, an empty dependency array, and a dependency array containing values.

12

Explain effect cleanup in React. When is a cleanup function executed, and why is it necessary?

13

Describe how asynchronous data fetching can be managed using useEffect. Discuss cleanup and race-condition handling.

14

Explain the purpose and operation of the useContext hook. Mention its benefits and performance considerations.

15

Differentiate between useCallback and useMemo. Give suitable use cases for both hooks.

16

Discuss React performance optimization with reference to re-renders, React.memo, useCallback, and useMemo.

17

What is a custom hook in React? Explain how custom hooks support logic reuse, with an example.

18

State and explain the Rules of Hooks. Why must hooks be called in a consistent order?

19

Identify and explain common pitfalls and anti-patterns associated with useEffect and its dependency array.

20

Analyze the following React code and explain why it may produce incorrect or inefficient behavior. Suggest an improved approach.

function Search({ items }) {
  const [query, setQuery] = useState("");
  const [results, setResults] = useState([]);

  useEffect(() => {
    setResults(items.filter(item => item.includes(query)));
  }, [query]);

  return <ResultList results={results} />;
}