In React Transition Group, what prop is used to define the duration of an exit animation?

  • transitionDuration
  • animationDuration
  • exitDuration
  • duration
In React Transition Group, the prop used to define the duration of an exit animation is exitDuration. This prop allows you to control how long it takes for a component to animate out of the view when it's being removed. The other options (transitionDuration, animationDuration, and duration) are not specific to exit animations in React Transition Group.

How can you ensure a component does not re-render unnecessarily when consuming a context?

  • Using memoization techniques like React.memo().
  • Implementing context with useState.
  • Wrapping the component with React.StrictMode.
  • Increasing the component's complexity.
To prevent unnecessary re-renders when consuming context, you can use memoization techniques like React.memo(). This higher-order component wraps the component and only re-renders it when its props or context values change. It's a performance optimization technique to avoid unnecessary re-renders, especially when the component depends on context values. The other options are not related to preventing re-renders due to context consumption.

In a MobX-powered e-commerce application, you want to ensure that the cart total is automatically updated whenever an item is added or its quantity is changed. Which approach would you use to achieve this efficient update?

  • Actions
  • Computed Properties
  • Observables
  • Reactions
To achieve an efficient update of the cart total in response to changes in items or their quantities, you would use Reactions in MobX. Reactions are triggered automatically when observable data they depend on changes. In this case, a reaction can recalculate the cart total whenever the cart items or their quantities change, ensuring an automatic and efficient update.

What happens if you modify an observable outside of an action in strict mode in MobX?

  • A warning is issued, but the modification is applied.
  • An error is thrown.
  • No effect, it's allowed in strict mode.
  • The modification is automatically batched.
In MobX strict mode, modifying an observable outside of an action results in an error being thrown. This is a fundamental principle to ensure that state changes are predictable and follow clear patterns. It helps prevent unintentional side effects and maintains the reactivity system's integrity.

What considerations should be taken into account when deciding the expiration time for cached assets in a PWA?

  • Network latency, asset size, and the frequency of updates.
  • The browser's cache size, the user's device type, and CPU usage.
  • The popularity of the asset, the development team's preferences, and the server's load.
  • The user's geolocation, the asset's file type, and the project budget.
When deciding the expiration time for cached assets in a Progressive Web App (PWA), several factors must be considered, including network latency (which affects download times), asset size (as larger assets take longer to download), and the frequency of updates (more frequent updates may require shorter cache times to ensure users receive the latest content). These considerations impact the user experience and performance of the PWA.

What is the main advantage of using Render Props over Higher Order Components (HOCs) in React?

  • Better performance and rendering speed.
  • Improved component reusability and composability.
  • Simplicity and ease of use.
  • Stronger typing and static analysis.
The main advantage of using Render Props over Higher Order Components (HOCs) in React is improved component reusability and composability. Render Props make it easier to share logic between components and are more flexible than HOCs, which can lead to more maintainable and readable code. While HOCs have their own benefits, they may not offer the same level of flexibility as Render Props.

In React-Redux, the hook that allows you to extract data from the Redux store is ________.

  • connect
  • mapDispatchToProps
  • useEffect
  • useSelector
In React-Redux, the hook used to extract data from the Redux store is useSelector. This hook allows you to select data from the store's state and use it in your components. mapDispatchToProps is used for dispatching actions, connect is a higher-order component for connecting React components to the store, and useEffect is used for side effects.

What does the term 'immutable state' mean in the context of React and Redux?

  • State that can only be changed by Redux actions
  • State that cannot be changed after it's created
  • State that is passed as a prop to child components only
  • State that is stored in a global context
In the context of React and Redux, 'immutable state' refers to state that cannot be changed after it's created. In Redux, state immutability is a core principle. Instead of modifying the existing state, a new state object is created with the desired changes. This immutability ensures predictability and helps in tracking state changes, making debugging and testing easier.

Even though a Portal can be anywhere in the DOM tree, it behaves like a normal React child in every other way, especially concerning event bubbling.

  • Component nesting
  • Event bubbling
  • Event handling
  • Propagation
React Portals, despite their ability to exist anywhere in the DOM tree, behave like normal React children when it comes to event handling, including event bubbling. This means that events triggered inside a portal can bubble up to their ancestors in the React component hierarchy.

How would you implement event delegation in a React application?

  • Create separate event listeners for each element.
  • Implement event delegation using Redux.
  • Use the addEventListener method.
  • Utilize the useEffect hook for delegation.
To implement event delegation in a React application, you should create separate event listeners for each element. This approach involves attaching a single event listener to a common ancestor and utilizing event propagation to handle events for multiple elements efficiently. It's a common technique to reduce the number of event handlers and optimize performance in large-scale React applications.