React Native

Performance Optimization

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

24 pytań z rozmów·
Senior
1

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

Odpowiedź

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?

Odpowiedź

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?

Odpowiedź

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 pytań z rozmów

Opanuj React Native na następną rozmowę

Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.

Zacznij za darmo