When using the map function to render a list in JSX, it's important to provide a unique ________ to each item.

  • Class
  • Element
  • Index
  • Key
When rendering lists in JSX using the map function, it's crucial to provide a unique "key" to each item. This "key" is used by React to efficiently update and re-render elements in the list when needed. Using a unique key helps React identify which elements have changed, been added, or been removed, optimizing performance and preventing rendering issues.

You're building an application where certain operations should only be performed when specific observable properties change. How would you set up a reaction that specifically listens to these properties in MobX?

  • When
  • autorun()
  • computed()
  • reaction()
To set up a reaction that specifically listens to certain observable properties in MobX, you would use the reaction() function. The reaction() function allows you to define custom reactions that depend on specific observables. When the specified observables change, the reaction is triggered, allowing you to perform the desired operations. This approach is suitable when you need fine-grained control over reactions.

In JSX, the HTML attribute class is replaced with ________.

  • class
  • className
  • classTag
  • cssClass
In JSX, the HTML attribute class is replaced with className. This is because class is a reserved keyword in JavaScript, and JSX is a JavaScript extension. To apply CSS classes to JSX elements, you should use className instead of class.

If you want to persist state across re-renders without causing any side effect, you'd use the ________ hook.

  • useContext
  • useEffect
  • useMemo
  • useRef
When you want to persist state across re-renders without causing any side effects, the useRef hook is typically used. Unlike other hooks like useEffect or useMemo, useRef does not trigger re-renders or side effects, making it ideal for maintaining mutable values that persist between renders.

Which of the following considerations is most crucial when scaling a React application with thousands of active Websocket connections?

  • Minimize the usage of server-sent events (SSE) for real-time updates.
  • Optimize server-side code and infrastructure to handle concurrent connections.
  • Use traditional HTTP polling instead of Websockets for better scalability.
  • Decrease the number of components that subscribe to Websocket updates.
When scaling a React application with thousands of active Websocket connections, the most crucial consideration is optimizing server-side code and infrastructure to handle concurrent connections (Option 2). This ensures that the server can manage the load effectively. The other options do not address the scalability challenges associated with a large number of Websocket connections. Server-sent events (SSE) and HTTP polling are not necessarily better alternatives for real-time updates. Reducing the number of subscribing components may impact the application's functionality.

How does "styled-components" library in React allow for dynamic styling?

  • It generates random styles for each component.
  • It imports external CSS files.
  • It relies on inline HTML styling.
  • It uses a JavaScript object to define styles.
"styled-components" in React allows for dynamic styling by using a JavaScript object to define styles. This approach allows you to use JavaScript logic, including the use of props, to conditionally apply styles to components. Unlike traditional CSS, which is static, styled-components provides a more dynamic way to manage styles in your React application.

How does Immer produce a new state without deep cloning all objects in the state tree?

  • It creates a completely new state tree from scratch.
  • It relies on JavaScript's native deep cloning functions.
  • It uses a third-party library for cloning.
  • It utilizes structural sharing to create a new state.
Immer employs structural sharing, also known as "copy-on-write," to generate a new state without deep cloning all objects. When changes are made, only the affected objects are cloned, reducing memory and CPU usage. This technique is crucial for efficient state management in applications, particularly in React and Redux.

For managing complex state logic in functional components, which hook would be most appropriate?

  • useEffect
  • useReducer
  • useRef
  • useState
To manage complex state logic in functional components, the most appropriate hook is useReducer. It's especially useful when you have complex state that depends on previous state or when you need to manage multiple related state values. useEffect is for handling side effects, useRef for accessing DOM elements and persisting values, and useState for basic state management.

The concept in React which allows for the batching of multiple set state calls to improve performance is known as ________.

  • Batched State Updating
  • Concurrent Mode
  • React State Optimization
  • State Accumulation
The concept in React which allows for the batching of multiple setState calls to improve performance is known as "Batched State Updating." React batches state updates to minimize the number of re-renders and optimize performance. While Concurrent Mode is an important React feature, it's not specifically related to the batching of state updates.

To get a mutable ref object, which hook would you use?

  • useCallback
  • useContext
  • useMemo
  • useRef
To get a mutable ref object in React, you would use the "useRef" hook. This hook allows you to create a mutable ref object that can be attached to DOM elements or used for various purposes like accessing and modifying the DOM directly.