In MobX, which feature allows you to track changes to your state?

  • Actions.
  • Decorators.
  • Observables.
  • Promises.
In MobX, you can track changes to your state using "Observables." Observables are the fundamental building blocks that enable you to automatically detect and track changes in your application state. Actions are used to modify state, decorators are used for defining computed properties, and Promises are typically used for handling asynchronous operations but do not directly track state changes.

While rendering a list of items, you observed that adding a new item to the top causes a re-render of the entire list. What might be the likely cause of this issue?

  • Applying shouldComponentUpdate() to the list components
  • Incorrect use of React fragments
  • Missing unique keys in the list elements
  • Using React.memo() for list components
When adding a new item to a list in React, it's essential to provide unique keys to each list item using the "key" prop. If unique keys are missing or incorrectly assigned, React cannot efficiently identify which items have changed, and it may re-render the entire list. Using React.memo() can help optimize functional components, but it's unrelated to this specific issue. React fragments and shouldComponentUpdate() do not directly address the key issue.

The ________ method allows you to manually determine if a component should re-render in response to a change in props or state.

  • componentDidMount
  • render
  • setState
  • shouldComponentUpdate
The shouldComponentUpdate method in React allows developers to manually determine whether a component should re-render in response to changes in props or state. This method returns a Boolean value - true if the component should re-render and false if it should not. It's a critical method for optimizing React components to avoid unnecessary rendering.

JSX gets compiled into ________ by tools like Babel.

  • CSS
  • HTML
  • JavaScript
  • XML
JSX (JavaScript XML) gets compiled into JavaScript by tools like Babel. It's important to understand that JSX is a syntax extension for JavaScript, allowing developers to write HTML-like code within their JavaScript files. This JSX code is then transformed into standard JavaScript code that browsers can understand.

The strategy that prioritizes network requests over cache, but falls back to cache if the network is unavailable, is called ________.

  • Cache-First
  • Cache-Only
  • Network-First
  • Network-Only
The strategy that prioritizes network requests over cache but falls back to cache if the network is unavailable is called "Cache-First." This approach optimizes performance by serving cached content when possible while ensuring the latest data is fetched when the network is available, making it a common strategy for progressive web applications (PWAs) and service workers.

For pages that need to be private and can't be pre-rendered, Next.js recommends using ________.

  • getServerSideProps()
  • getStaticPaths()
  • getStaticProps()
  • useEffect()
When you have pages that need to be private and cannot be pre-rendered, Next.js recommends using getServerSideProps(). This function allows you to fetch data on the server for each request, making it suitable for dynamic or private content that cannot be statically generated. getStaticPaths() and getStaticProps() are typically used for pre-rendering, while useEffect() is a React hook and not directly related to server-side rendering.

Which of the following is a key difference between styling in React for web and React Native?

  • React for web requires external libraries for styling, while React Native has built-in styles.
  • React for web supports responsive design, while React Native does not.
  • React for web uses CSS for styling, while React Native uses JavaScript-based styles.
  • React for web uses inline styles, while React Native uses external CSS files.
A significant difference between React for web and React Native is that React for web uses CSS for styling, while React Native uses JavaScript-based styles. In React Native, styles are applied using JavaScript objects, providing a more native feel and allowing for better performance and flexibility when styling components.

In React Testing Library, to find an element by its role, you can use the query ________.

  • findByAttribute
  • findByElement
  • findByRole
  • queryByAttribute
In React Testing Library, to find an element by its role, you can use the query findByRole(). This query is especially useful when you want to locate elements based on their accessibility roles, such as finding buttons, links, or other interactive elements. It helps ensure your tests are more accessible and accurately represent how users interact with your React components.

How does Immutable.js ensure that data remains immutable?

  • By converting all data to primitive types.
  • By disallowing any updates or modifications to the data.
  • By creating copies of data objects whenever updates are made.
  • By using structural sharing and creating new objects for changes.
Immutable.js maintains data immutability by using structural sharing. When a change is made, a new object is created with the updated data, while the original data remains unchanged. This ensures immutability without the need for deep copying, making it more memory-efficient. The other options do not accurately describe how Immutable.js achieves data immutability.

What is the primary purpose of the React hook useState?

  • To manage and update component state.
  • To create reusable components.
  • To perform API requests.
  • To handle router navigation.
The primary purpose of the React hook useState is to manage and update component state. It allows functional components to have stateful behavior, which is crucial for handling dynamic data and user interactions. The other options (create reusable components, perform API requests, and handle router navigation) are not the primary purpose of useState.

What is the purpose of the setState method in React class components?

  • To define a new component in React.
  • To update and re-render the component with new data.
  • To handle HTTP requests in React applications.
  • To declare a function in a React component.
The setState method in React class components is used to update and re-render the component with new data. It's essential for managing the component's internal state and triggering re-renders when that state changes. Options 1, 3, and 4 do not accurately describe the purpose of setState.

What is the main purpose of Google Maps integration in a React application?

  • Displaying real-time weather information.
  • Enabling social media sharing.
  • Enhancing the user interface with interactive maps.
  • Managing state in React components.
Google Maps integration in a React application is primarily used to enhance the user interface by adding interactive maps. Developers can integrate Google Maps to display locations, directions, or any spatial data, making their applications more user-friendly and engaging. It's a common choice for applications that require geolocation features.