React Native

Performance Optimization

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

24 câu hỏi phỏng vấn·
Senior
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững React Native cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí