Q. What is the main purpose of useEffect in React?

  • (A) To update props
  • (B) To perform side effects
  • (C) To create components
  • (D) To render JSX
πŸ’¬ Discuss
βœ… Correct Answer: (B) To perform side effects
Explanation: useEffect is used to perform side effects such as data fetching or subscriptions.

Q. Which of the following will NOT cause a component to re-render?

  • (A) State change
  • (B) Prop change
  • (C) Context change
  • (D) Local variable change
πŸ’¬ Discuss
βœ… Correct Answer: (D) Local variable change
Explanation: Changing a local variable won't trigger a re-render in React.

Q. Which hook allows you to access the DOM element directly?

  • (A) useEffect
  • (B) useMemo
  • (C) useRef
  • (D) useState
πŸ’¬ Discuss
βœ… Correct Answer: (C) useRef
Explanation: useRef provides a way to access and persist a reference to a DOM element.

Q. Which lifecycle method is equivalent to useEffect with an empty dependency array?

  • (A) componentDidMount
  • (B) componentDidUpdate
  • (C) componentWillUnmount
  • (D) shouldComponentUpdate
πŸ’¬ Discuss
βœ… Correct Answer: (A) componentDidMount
Explanation: useEffect with an empty array runs only once, just like componentDidMount in class components.

Q. In JSX, how do you write a JavaScript expression?

  • (A) With double quotes
  • (B) With parentheses
  • (C) With square brackets
  • (D) With curly braces
πŸ’¬ Discuss
βœ… Correct Answer: (D) With curly braces
Explanation: JSX expressions are enclosed within curly braces.

Q. Which of these is not a valid React event?

  • (A) onClick
  • (B) onSubmit
  • (C) onHover
  • (D) onChange
πŸ’¬ Discuss
βœ… Correct Answer: (C) onHover
Explanation: React uses onMouseOver instead of onHover.

Q. What will happen if you modify state directly in React?

  • (A) Component re-renders correctly
  • (B) State change is ignored
  • (C) React throws an error
  • (D) Component may behave unexpectedly
πŸ’¬ Discuss
βœ… Correct Answer: (D) Component may behave unexpectedly
Explanation: Direct state mutation can lead to bugs and unpredictable behavior.

Q. What is the output of React.createElement?

  • (A) HTML element
  • (B) JSX code
  • (C) React element
  • (D) DOM node
πŸ’¬ Discuss
βœ… Correct Answer: (C) React element
Explanation: React.createElement returns a React element, not an actual DOM node.

Q. What does a React component return?

  • (A) String
  • (B) Object
  • (C) JSX
  • (D) HTML
πŸ’¬ Discuss
βœ… Correct Answer: (C) JSX
Explanation: React components return JSX, which is transpiled to React.createElement calls.

Q. Which command is used to start a React app in development mode?

  • (A) npm start
  • (B) npm build
  • (C) npm install
  • (D) npm test
πŸ’¬ Discuss
βœ… Correct Answer: (A) npm start
Explanation: npm start runs the app in development mode.