React Native

Performance Optimization

FlatList optimization, memo, useMemo/useCallback, Hermes, profiling, bundle size

24 domande da colloquio·
Senior
1

What is the main role of React.memo in React Native performance optimization?

Risposta

React.memo is a Higher-Order Component that memoizes the render result of a functional component. It prevents unnecessary re-renders by comparing current props with previous ones (shallow comparison by default). If props haven't changed, React reuses the memoized result instead of re-rendering the component, which significantly improves performance in lists or complex component trees.

2

Which FlatList property significantly optimizes scrolling by providing item dimensions in advance?

Risposta

getItemLayout is an optional FlatList property that allows pre-calculating the height, width, and offset of each item. This prevents React Native from dynamically measuring each item, which considerably improves scroll performance, especially when jumping to a specific index with scrollToIndex. This optimization is particularly useful when all items have the same size.

3

What is the main difference between useMemo and useCallback in terms of optimization?

Risposta

useMemo memoizes the result of an expensive calculation and returns that computed value, while useCallback memoizes a function itself and returns that function. useMemo is useful for avoiding heavy recalculations on each render, whereas useCallback is essential for avoiding recreating functions passed as props to memoized child components, which would break their React.memo optimization.

4

What is Hermes and what is its main advantage for React Native applications?

5

Why is it crucial to provide a stable keyExtractor function to FlatList?

+21 domande da colloquio

Padroneggia React Native per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis