πŸ“Š React Js
Q. Which of these is a valid way to pass props to a component?
Code:
<MyComponent title="React" />
  • (A) title: 'React'
  • (B) MyComponent.props('React')
  • (C) <MyComponent title="React" />
  • (D) MyComponent[title='React']
πŸ’¬ Discuss
βœ… Correct Answer: (C) <MyComponent title="React" />

Explanation: Props are passed to components using JSX attributes like in HTML.

πŸ“Š React Js
Q. Which React hook is best suited for managing complex state logic?
  • (A) useState
  • (B) useReducer
  • (C) useEffect
  • (D) useCallback
πŸ’¬ Discuss
βœ… Correct Answer: (B) useReducer

Explanation: useReducer is ideal for handling more complex state transitions.

πŸ“Š React Js
Q. Which of the following correctly describes React's data flow?
  • (A) Two-way binding
  • (B) Circular flow
  • (C) Unidirectional flow
  • (D) Bidirectional flow
πŸ’¬ Discuss
βœ… Correct Answer: (C) Unidirectional flow

Explanation: React follows a unidirectional data flow from parent to child via props.

πŸ“Š React Js
Q. Which statement about props is correct?
  • (A) Props are mutable
  • (B) Props can only be passed to class components
  • (C) Props help pass data to components
  • (D) Props are used to store state
πŸ’¬ Discuss
βœ… Correct Answer: (C) Props help pass data to components

Explanation: Props are used to pass data and event handlers to child components.

πŸ“Š React Js
Q. What is the use of Fragment in React?
  • (A) To apply CSS styling
  • (B) To manage routing
  • (C) To wrap multiple elements without adding extra nodes to the DOM
  • (D) To format JSON data
πŸ’¬ Discuss
βœ… Correct Answer: (C) To wrap multiple elements without adding extra nodes to the DOM

Explanation: Fragments let you group multiple elements without creating extra DOM nodes.

πŸ“Š React Js
Q. What does the useMemo hook do?
  • (A) Returns a memoized callback
  • (B) Returns a memoized value
  • (C) Returns a cleanup function
  • (D) Returns a component
πŸ’¬ Discuss
βœ… Correct Answer: (B) Returns a memoized value

Explanation: useMemo returns a memoized value to optimize performance.

πŸ“Š React Js
Q. Which hook should be used to avoid re-creating functions on every render?
  • (A) useState
  • (B) useEffect
  • (C) useCallback
  • (D) useMemo
πŸ’¬ Discuss
βœ… Correct Answer: (C) useCallback

Explanation: useCallback returns a memoized version of a callback function.

πŸ“Š React Js
Q. In which file is the root React component typically rendered?
  • (A) App.js
  • (B) Main.js
  • (C) Index.js
  • (D) Root.js
πŸ’¬ Discuss
βœ… Correct Answer: (C) Index.js

Explanation: index.js is the entry point where the root React component is rendered into the DOM.

πŸ“Š React Js
Q. What does React.StrictMode do?
  • (A) Disables JSX
  • (B) Checks for potential problems in code
  • (C) Blocks state updates
  • (D) Optimizes rendering
πŸ’¬ Discuss
βœ… Correct Answer: (B) Checks for potential problems in code

Explanation: StrictMode is used to highlight potential problems in an application during development.

πŸ“Š React Js
Q. Which method is used to update state in a class component?
  • (A) this.state
  • (B) setState
  • (C) updateState
  • (D) changeState
πŸ’¬ Discuss
βœ… Correct Answer: (B) setState

Explanation: In class components, state is updated using the setState method.