Câu hỏi phỏng vấn React Native
Câu hỏi

What is the use of FlatList?

Câu trả lời

The FlatList component in React Native is used to efficiently render large lists of data in a scrollable view. It is designed to handle dynamic and potentially large datasets by only rendering the items that are currently visible on the screen, which optimizes performance and memory usage.

Key Features and Uses of FlatList:

  1. Efficient Rendering:

    • FlatList only renders the items that are currently visible on the screen, rather than all items at once. This lazy loading approach helps in managing memory and improving performance, especially for long lists of data[4][6].
  2. Required Props:

    • data: An array of items to be rendered.
    • renderItem: A function that takes an item from the data array and returns a formatted component to render[1][4][6].
  3. Optional Props:

    • keyExtractor: A function to extract a unique key for each item, which helps in efficient re-rendering.
    • ItemSeparatorComponent: A component to render between each item.
    • ListHeaderComponent and ListFooterComponent: Components to render at the top and bottom of the list, respectively.
    • horizontal: A boolean to render the list horizontally instead of vertically.
    • numColumns: A prop to render multiple columns[1][6][8].
  4. Performance Optimizations:

    • FlatList supports various performance optimizations such as removeClippedSubviews, getItemLayout, and maxToRenderPerBatch to further enhance the rendering efficiency[9].
  5. Use Cases:

    • FlatList is ideal for scenarios where you need to display a large number of items, such as a list of contacts, messages, or any other data that can grow dynamically. It is also suitable for implementing infinite scrolling and pull-to-refresh functionalities[1][3][6].

Example Usage:

javascript Copy
import React from 'react';
import { FlatList, Text, View, StyleSheet } from 'react-native';

const DATA = [
  { id: '1', title: 'Item 1' },
  { id: '2', t...
middle

middle

Gợi ý câu hỏi phỏng vấn

junior

What are the advantages of native apps over hybrid apps?

middle

What is View and how important is it?

middle

In Fast Refresh, what will happen if you edit files imported by modules outside of the React Tree?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào