Q. What is the correct way to create a component in React?

  • (A) function MyComponent()
  • (B) createComponent()
  • (C) Component.create()
  • (D) new Component()
πŸ’¬ Discuss
βœ… Correct Answer: (A) function MyComponent()
Explanation: Functional components in React are defined using regular functions.

Q. What does `useCallback` hook do?

  • (A) It returns a new function every time
  • (B) It memoizes a function to avoid unnecessary re-creation
  • (C) It creates a new state
  • (D) It modifies context
πŸ’¬ Discuss
βœ… Correct Answer: (B) It memoizes a function to avoid unnecessary re-creation
Explanation: useCallback returns a memoized version of a callback that only changes if dependencies change.

Q. How do you create context in React?

  • (A) React.setContext()
  • (B) React.createContext()
  • (C) useContextProvider()
  • (D) contextHook()
πŸ’¬ Discuss
βœ… Correct Answer: (B) React.createContext()
Explanation: React.createContext() is used to create a new context.

Q. What is the purpose of `useLayoutEffect`?

  • (A) Same as useEffect but runs synchronously after DOM mutations
  • (B) It delays rendering
  • (C) It blocks the DOM update
  • (D) It resets the DOM
πŸ’¬ Discuss
βœ… Correct Answer: (A) Same as useEffect but runs synchronously after DOM mutations
Explanation: useLayoutEffect runs synchronously after all DOM mutations.

Q. In React, what is reconciliation?

  • (A) Process of compiling JSX
  • (B) Matching new tree with old tree to update DOM
  • (C) Re-rendering all components
  • (D) Synchronizing with backend
πŸ’¬ Discuss
βœ… Correct Answer: (B) Matching new tree with old tree to update DOM
Explanation: Reconciliation is the process of comparing the new virtual DOM with the previous one.

Q. Which hook would you use to share logic between components?

  • (A) useEffect
  • (B) useState
  • (C) Custom Hook
  • (D) useReducer
πŸ’¬ Discuss
βœ… Correct Answer: (C) Custom Hook
Explanation: Custom Hooks allow you to extract and reuse stateful logic between components.

Q. What is a pure component in React?

  • (A) A component with no JSX
  • (B) A component that never updates
  • (C) A component that renders the same output for the same props
  • (D) A component with only CSS
πŸ’¬ Discuss
βœ… Correct Answer: (C) A component that renders the same output for the same props
Explanation: Pure components prevent unnecessary re-renders by doing a shallow comparison of props and state.

Q. Which of the following is used to handle side effects in React functional components?

  • (A) useEffect
  • (B) useState
  • (C) useRef
  • (D) useContext
πŸ’¬ Discuss
βœ… Correct Answer: (A) useEffect
Explanation: useEffect is used for handling side effects like data fetching, subscriptions, and manual DOM manipulation.

Q. How can we optimize performance for a large list in React?

  • (A) Using pure components only
  • (B) Using keys only
  • (C) Using React.lazy
  • (D) Using windowing techniques like react-window
πŸ’¬ Discuss
βœ… Correct Answer: (D) Using windowing techniques like react-window
Explanation: Windowing libraries like react-window render only visible items, improving performance.

Q. What does 'lifting state up' mean in React?

  • (A) Moving state to Redux store
  • (B) Moving state to a common parent component
  • (C) Passing state as props downward
  • (D) Using useRef instead of useState
πŸ’¬ Discuss
βœ… Correct Answer: (B) Moving state to a common parent component
Explanation: Lifting state up involves moving shared state to the closest common ancestor component.