For properties that should recompute only when the data they depend upon changes, you use the MobX ________ decorator.

  • @action
  • @autorun
  • @computed
  • @observer
To make properties recompute only when the data they depend upon changes, you use the @computed decorator in MobX. This decorator creates a computed property, which automatically updates itself when the observed data changes. The other decorators (@action, @observer, @autorun) serve different purposes and do not create computed properties.

What is the primary role of Redux in a React application?

  • Handling component rendering.
  • Managing global state.
  • Styling React components.
  • Routing in React.
Redux's primary role in a React application is to manage global state. It provides a centralized store for application data that can be accessed by different components. While the other options are important aspects of a React application, such as rendering, styling, and routing, they are not the primary role of Redux.

In React Router, which component is primarily used to define a specific path and its corresponding component?

  • BrowserRouter
  • Link
  • Route
  • Switch
In React Router, the Route component is primarily used to define a specific path and its corresponding component. When a user navigates to a specified URL path, the associated component is rendered. This is fundamental for setting up routing in a React application using React Router.

In React Router, the ________ component is used to link to different parts of the application.

In React Router, the component is used to create links to different parts of the application. It allows users to navigate between different views or components without a full page reload. The other options, such as , , and , serve different purposes in routing.

In the diffing process, when comparing lists, React uses the ________ attribute to determine which items have changed.

  • class
  • id
  • key
  • ref
In React, the key attribute is used during the diffing process to identify which items in a list have changed. The key prop helps React efficiently update the UI by associating elements with their previous versions, ensuring that only the necessary changes are applied.

Which HTTP header is crucial for implementing a cache-first strategy in service workers?

  • Cache-Control: max-age
  • Cache-Control: no-cache
  • Cache-Control: no-store
  • Cache-Control: public, max-age
Implementing a cache-first strategy in service workers requires the use of the Cache-Control HTTP header with directives like public and max-age. By specifying public, you allow the response to be cached, and max-age sets the maximum time that the response should be considered fresh. This strategy ensures that the service worker prioritizes cached responses over network requests when possible, enhancing performance and offline capabilities.

How can you enhance the performance of a Redux-connected component when its state changes frequently?

  • Increase the use of Redux Thunk middleware for faster dispatch.
  • Use a higher-order component (HOC) to wrap the Redux-connected component.
  • Use memoization techniques like reselect to optimize mapStateToProps.
  • Utilize Redux middleware for caching frequently changing state.
To enhance the performance of a Redux-connected component when its state changes frequently, you can use memoization techniques like Reselect to optimize mapStateToProps. Reselect helps prevent unnecessary re-renders by caching the results of expensive calculations based on the state. Increasing the use of Redux Thunk middleware or using a higher-order component (HOC) isn't directly related to optimizing component performance. Redux middleware for caching is not a common approach for this purpose.

How does Webpack facilitate lazy loading of code chunks in an application?

  • Through code splitting and dynamic imports.
  • By using multiple entry points in the Webpack configuration.
  • Webpack doesn't support lazy loading.
  • By minimizing the JavaScript bundle size.
Webpack facilitates lazy loading of code chunks in an application through code splitting and dynamic imports. It allows developers to break down their application into smaller code chunks that can be loaded on-demand, reducing the initial load time and improving performance. The other options are not accurate representations of how Webpack enables lazy loading.

When working with WebSockets in React, the ________ library provides a convenient way to establish and manage socket connections.

  • Axios
  • Express.js
  • Redux-WebSocket
  • Socket.io
When working with WebSockets in React, the Socket.io library provides a convenient way to establish and manage socket connections. Socket.io is a popular library that offers real-time, bidirectional communication between clients and the server, making it a common choice for WebSocket functionality in React applications. Express.js is a server-side framework, Redux-WebSocket doesn't handle WebSocket connections directly, and Axios is used for making HTTP requests.

To instantiate a new Web Worker, you'd typically use the ________ constructor.

  • Worker()
  • NewWorker()
  • CreateWorker()
  • WebWorker()
To create a new Web Worker, you typically use the Worker() constructor in JavaScript. This constructor is responsible for creating a new worker that can run JavaScript code in the background. The other options are not the correct constructor names for creating Web Workers.