πŸ“Š React Js
Q. What is the purpose of the useState hook in React?
  • (A) To perform side effects
  • (B) To manage component state
  • (C) To fetch data from API
  • (D) To navigate between pages
πŸ’¬ Discuss
βœ… Correct Answer: (B) To manage component state

Explanation: The useState hook is used to create and manage local component state in functional components.

πŸ“Š React Js
Q. Which method is used to render React components to the DOM?
  • (A) React.render()
  • (B) ReactDOM.render()
  • (C) renderComponent()
  • (D) Component.render()
πŸ’¬ Discuss
βœ… Correct Answer: (B) ReactDOM.render()

Explanation: ReactDOM.render() is used to render a React element into the DOM.

πŸ“Š React Js
Q. In React, what is JSX?
  • (A) A templating engine
  • (B) A type of CSS
  • (C) JavaScript XML syntax for defining UI
  • (D) A server-side scripting language
πŸ’¬ Discuss
βœ… Correct Answer: (C) JavaScript XML syntax for defining UI

Explanation: JSX is a syntax extension that allows mixing HTML with JavaScript.

πŸ“Š React Js
Q. Which hook is used to perform side effects in functional components?
  • (A) useState
  • (B) useEffect
  • (C) useReducer
  • (D) useRef
πŸ’¬ Discuss
βœ… Correct Answer: (B) useEffect

Explanation: The useEffect hook is used to perform side effects like data fetching or DOM manipulation.

πŸ“Š React Js
Q. What is the virtual DOM in React?
  • (A) A real DOM in memory
  • (B) A UI rendered in JavaScript
  • (C) A lightweight in-memory representation of the real DOM
  • (D) A CSS engine
πŸ’¬ Discuss
βœ… Correct Answer: (C) A lightweight in-memory representation of the real DOM

Explanation: The virtual DOM is a lightweight copy of the real DOM that React uses for efficient updates.

πŸ“Š React Js
Q. What is the default state of a new useState variable?
Code:
const [count, setCount] = useState();
  • (A) 0
  • (B) undefined
  • (C) null
  • (D) 1
πŸ’¬ Discuss
βœ… Correct Answer: (B) undefined

Explanation: If no argument is passed to useState, the default state is undefined.

πŸ“Š React Js
Q. Which method is used to pass data from parent to child in React?
  • (A) props
  • (B) state
  • (C) context
  • (D) dispatch
πŸ’¬ Discuss
βœ… Correct Answer: (A) props

Explanation: Props are used to pass data from parent to child components in React.

πŸ“Š React Js
Q. How do you prevent a component from re-rendering in React?
  • (A) By returning null in render
  • (B) By using React.memo
  • (C) By avoiding JSX
  • (D) By not using useState
πŸ’¬ Discuss
βœ… Correct Answer: (B) By using React.memo

Explanation: React.memo is a higher-order component that prevents re-rendering if props do not change.

πŸ“Š React Js
Q. What does the key prop do in React lists?
  • (A) It sets the list style
  • (B) It uniquely identifies elements for efficient updates
  • (C) It adds a password to components
  • (D) It defines accessibility
πŸ’¬ Discuss
βœ… Correct Answer: (B) It uniquely identifies elements for efficient updates

Explanation: Keys help React identify which items have changed, been added, or removed.

πŸ“Š React Js
Q. Which hook allows sharing logic between components in React?
  • (A) useCallback
  • (B) useState
  • (C) Custom hooks
  • (D) useEffect
πŸ’¬ Discuss
βœ… Correct Answer: (C) Custom hooks

Explanation: Custom hooks allow you to extract and reuse logic between components.