πŸ“Š React Js
Q. Which of the following best describes React?
  • (A) A full-stack framework
  • (B) A library for building user interfaces
  • (C) A server-side rendering engine
  • (D) A CSS framework
πŸ’¬ Discuss
βœ… Correct Answer: (B) A library for building user interfaces

Explanation: React is a JavaScript library focused on building user interfaces.

πŸ“Š React Js
Q. Which hook is used to memoize a callback function in React?
  • (A) useEffect
  • (B) useCallback
  • (C) useMemo
  • (D) useRef
πŸ’¬ Discuss
βœ… Correct Answer: (B) useCallback

Explanation: useCallback memoizes a callback to prevent unnecessary re-creation between renders.

πŸ“Š React Js
Q. Which React hook is used to store and persist a reference across renders?
  • (A) useMemo
  • (B) useReducer
  • (C) useRef
  • (D) useContext
πŸ’¬ Discuss
βœ… Correct Answer: (C) useRef

Explanation: useRef allows storing values that persist across renders without triggering re-renders.

πŸ“Š React Js
Q. Which statement is true about state in React?
  • (A) State can be changed directly
  • (B) State updates are synchronous
  • (C) State should be immutable
  • (D) State is used only in class components
πŸ’¬ Discuss
βœ… Correct Answer: (C) State should be immutable

Explanation: State should not be changed directly; it should be updated immutably using setState or state setters.

πŸ“Š React Js
Q. What will happen if you forget to include a key in a list item?
  • (A) React will crash
  • (B) Nothing, it's optional
  • (C) React will throw an error
  • (D) React may render inefficiently
πŸ’¬ Discuss
βœ… Correct Answer: (D) React may render inefficiently

Explanation: Without keys, React has difficulty optimizing list rendering.

πŸ“Š React Js
Q. What is the role of defaultProps in React?
  • (A) To define required props
  • (B) To apply default values to props
  • (C) To validate prop types
  • (D) To override parent props
πŸ’¬ Discuss
βœ… Correct Answer: (B) To apply default values to props

Explanation: defaultProps are used to set default values for props when not provided.

πŸ“Š React Js
Q. Which of the following is a valid custom hook name?
  • (A) useLogin
  • (B) LoginHook
  • (C) myHook
  • (D) hookUse
πŸ’¬ Discuss
βœ… Correct Answer: (A) useLogin

Explanation: Custom hooks must start with the word 'use' by convention.

πŸ“Š React Js
Q. How can you conditionally render a component in React?
  • (A) Using if statement outside JSX
  • (B) Using ternary operator or logical && inside JSX
  • (C) Using a loop
  • (D) You cannot conditionally render in React
πŸ’¬ Discuss
βœ… Correct Answer: (B) Using ternary operator or logical && inside JSX

Explanation: Conditional rendering in JSX is commonly done using ternary or &&.

πŸ“Š React Js
Q. Which of the following is used to install React?
  • (A) npm install create-react-app
  • (B) npm create react-app
  • (C) npx create-react-app
  • (D) npx init react
πŸ’¬ Discuss
βœ… Correct Answer: (C) npx create-react-app

Explanation: npx create-react-app is used to bootstrap a new React application.

πŸ“Š React Js
Q. Which tag is necessary to wrap multiple elements in JSX?
  • (A) <div>
  • (B) <section>
  • (C) <React.Fragment>
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above

Explanation: You can wrap with any single parent element, including div, section, or React.Fragment.