Which HTTP method is commonly used to request data from a server without making any modifications?

  • GET
  • POST
  • PUT
  • DELETE
The HTTP method commonly used to request data from a server without making any modifications is GET. It's a safe and idempotent method used for retrieving data from a specified resource without altering it. The other options, POST, PUT, and DELETE, are typically used for modifying or deleting resources on the server.

When creating a custom hook, it's a convention to start the hook's name with ________.

  • custom
  • hook
  • react
  • use
When creating a custom hook in React, it's a convention to start the hook's name with "use." This naming convention is essential for the hook to work correctly and to indicate to other developers that it is intended to be used as a custom React hook.

Which of the following best describes the concept of "prop drilling"?

  • Managing component state using props.
  • Passing data directly between sibling components.
  • Passing data from parent to child components.
  • Using props to style React components.
"Prop drilling" refers to the practice of passing data directly between sibling components, bypassing the parent component. This can lead to a complex chain of prop-passing, making the code harder to maintain. It is not about passing data from parent to child components or managing component state using props. Styling with props is a different concept altogether.

In what scenario would the useRef hook be particularly useful?

  • Accessing and interacting with DOM elements directly.
  • Handling side effects in useEffect.
  • Implementing a custom hook.
  • Managing component state.
The useRef hook is primarily useful for accessing and interacting with DOM elements directly. It provides a way to create mutable references to DOM nodes and is often used for tasks like managing focus, triggering imperative animations, or integrating third-party libraries. While it can be used in other scenarios, its most significant advantage lies in its ability to work with the DOM.

How does React behave if an error is not caught by any error boundary?

  • React will automatically catch and handle the error.
  • React will crash the entire application.
  • React will display a generic error message to the user.
  • React will log an error message to the console but continue rendering.
In React, if an error is not caught by any error boundary, it will lead to the application's crash. This is because unhandled errors in React components can't be gracefully managed, so React takes the approach of preserving the application's integrity by crashing it. It's essential to use error boundaries to capture and handle errors in a controlled manner.

React's way of handling events in a unified manner across different browsers is called ________.

  • Event Bubbling
  • Event Delegation
  • Event Handling
  • Synthetic Events
React's way of handling events in a unified manner across different browsers is called "Synthetic Events." It abstracts the native browser events and provides a consistent API for event handling in React components, making it easier to work with events in a cross-browser compatible way.

In which type of components can you directly use the setState method?

  • Both class-based and functional components
  • Class-based components
  • Functional components with hooks
  • Neither class-based nor functional components
You can directly use the setState method in class-based components. Functional components with hooks use the useState hook instead to manage state. So, setState is typically associated with class-based components, and using it in functional components will result in an error.

Error Boundaries in React catch errors during the rendering phase in any component below them in the tree, but they do not catch errors inside ________.

  • Asynchronous code
  • Class components
  • Event handlers
  • Function components
Error Boundaries in React are designed to catch errors during rendering but do not catch errors that occur inside asynchronous code (e.g., in setTimeout or fetch callbacks) or event handlers. It's important to understand this limitation when using Error Boundaries to handle errors in your React applications.

To ensure specificity in CSS Modules without using deep selectors, one could use the :global ______.

  • :deep
  • :not-global
  • :global-selector
  • :module
In CSS Modules, the ":global-selector" can be used to ensure specificity without resorting to deep selectors. ":global-selector" allows you to define styles that are not scoped to a specific module, making them accessible globally. The other options are not valid constructs in CSS Modules.

How would you handle reconnecting to a Websocket server in a React application if the connection drops?

  • Use the componentDidMount lifecycle method to establish a new connection.
  • Implement a reconnect mechanism using the onclose event and backoff strategies.
  • Continuously retry connecting in a loop within the render method.
  • Ask the user to refresh the page to restore the connection.
When a Websocket connection drops in a React application, it's essential to implement a reconnect mechanism. Option 2 is the correct approach, using the onclose event and backoff strategies to establish a new connection. The other options are not recommended as they can lead to suboptimal user experiences or performance issues.