Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

new_bird-hyun

React에서 대규모 데이터 처리와 가상화(Virtualization) 본문

코딩 공부

React에서 대규모 데이터 처리와 가상화(Virtualization)

새혀니 2025. 1. 7. 00:02

// npm install react-window

 

// VirtualizedList.js

import React from 'react';
import { FixedSizeList as List } from 'react-window';

const items = Array.from({ length: 10000 }, (_, i) => `Item ${i + 1}`);

export default function VirtualizedList() {
  return (
    <div>
      <h1>React Virtualized List</h1>
      <List
        height={400} // 리스트의 높이
        itemCount={items.length} // 항목 개수
        itemSize={35} // 각 항목의 높이
        width="100%" // 리스트의 너비
      >
        {({ index, style }) => (
          <div style={style}>
            {items[index]}
          </div>
        )}
      </List>
    </div>
  );
}

 

// App.js

import React from 'react';
import VirtualizedList from './VirtualizedList';

export default function App() {
  return (
    <div>
      <VirtualizedList />
    </div>
  );
}

 

// React Window를 활용하면 대규모 데이터를 효율적으로 처리 가능