Q. How can we prevent a component from re-rendering?

  • (A) Using useMemo only
  • (B) Using memo for functional components
  • (C) Avoid using props
  • (D) Using useEffect only
πŸ’¬ Discuss
βœ… Correct Answer: (B) Using memo for functional components
Explanation: memo can wrap functional components to prevent unnecessary re-renders.

Q. What is the default port for React development server?

  • (A) 3000
  • (B) 8080
  • (C) 5000
  • (D) 8000
πŸ’¬ Discuss
βœ… Correct Answer: (A) 3000
Explanation: React apps started with create-react-app run on port 3000 by default.

Q. Which of these is used to style React components?

  • (A) CSS
  • (B) Inline styles
  • (C) Styled-components
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above
Explanation: All listed methods can be used to style React components.

Q. What will happen if a hook is used inside a conditional statement?

  • (A) It will work fine
  • (B) React will ignore it
  • (C) React will throw an error
  • (D) It will be skipped on first render
πŸ’¬ Discuss
βœ… Correct Answer: (C) React will throw an error
Explanation: Hooks must be called unconditionally at the top level of a function component.

Q. What is the key difference between props and state in React?

  • (A) Props are mutable, state is immutable
  • (B) Props are used for internal data, state for external
  • (C) Props are passed, state is managed internally
  • (D) No difference
πŸ’¬ Discuss
βœ… Correct Answer: (C) Props are passed, state is managed internally
Explanation: Props are passed from parent to child, state is managed within a component.

Q. Which hook should you use to manage complex state logic?

  • (A) useState
  • (B) useRef
  • (C) useEffect
  • (D) useReducer
πŸ’¬ Discuss
βœ… Correct Answer: (D) useReducer
Explanation: useReducer is better for handling complex state logic compared to useState.

Q. What is returned by the useState hook?

  • (A) Only the current state value
  • (B) A function to update the state
  • (C) An array with current state and setter function
  • (D) A single object
πŸ’¬ Discuss
βœ… Correct Answer: (C) An array with current state and setter function
Explanation: useState returns a pair: current state and a function to update it.

Q. How do you pass data from a child to a parent component?

  • (A) Using props
  • (B) Using state
  • (C) Using callback functions
  • (D) Using refs
πŸ’¬ Discuss
βœ… Correct Answer: (C) Using callback functions
Explanation: A child can invoke a callback passed via props to send data to the parent.

Q. What is JSX?

  • (A) A templating engine
  • (B) A syntax extension for JavaScript
  • (C) A CSS preprocessor
  • (D) A database language
πŸ’¬ Discuss
βœ… Correct Answer: (B) A syntax extension for JavaScript
Explanation: JSX is a syntax extension that allows writing HTML-like code in JavaScript.

Q. Which method is used to pass props to a component?

  • (A) this.props()
  • (B) props.push()
  • (C) Passing them as attributes
  • (D) props.assign()
πŸ’¬ Discuss
βœ… Correct Answer: (C) Passing them as attributes
Explanation: Props are passed to components like HTML attributes in JSX.