react-simple-virtualize 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +16 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -35,25 +35,25 @@ const MyLargeList = () => {
35
35
  // 1. Setup your data
36
36
  const items = Array.from({ length: 10000 }, (_, i) => `Item ${i + 1}`);
37
37
 
38
- // 2. Define dimensions
39
- const containerHeight = 500;
40
- const itemHeight = 50;
41
-
42
- // 3. Initialize the hook
43
- const { virtualItems, totalHeight, onScroll } = useVirtualize({
38
+ // 2. Initialize the hook
39
+ const {
40
+ virtualItems,
41
+ totalHeight,
42
+ scrollRef,
43
+ onScroll
44
+ } = useVirtualize({
44
45
  itemCount: items.length,
45
- itemHeight,
46
- containerHeight,
47
- overscan: 5, // Optional: Number of items to render outside viewport
46
+ itemHeight: 50,
47
+ overscan: 5,
48
48
  });
49
49
 
50
50
  return (
51
- // Outer Container: Needs fixed height & overflow-y: auto
51
+ // Outer Container: Needs a size (fixed or flex) & overflow-y: auto
52
52
  <div
53
- onScroll={onScroll}
54
53
  ref={scrollRef}
54
+ onScroll={onScroll}
55
55
  style={{
56
- height: containerHeight,
56
+ height: '500px', // Or '100%', 'flex: 1'
57
57
  overflowY: 'auto',
58
58
  position: 'relative',
59
59
  border: '1px solid #ccc'
@@ -63,20 +63,20 @@ const MyLargeList = () => {
63
63
  <div style={{ height: totalHeight, position: 'relative' }}>
64
64
 
65
65
  {/* Render only visible items */}
66
- {virtualItems.map(({ index, offsetTop }) => (
66
+ {virtualItems.map(({ index, offsetTop, measureRef }) => (
67
67
  <div
68
68
  key={index}
69
- ref={virtualItem.measureRef}
69
+ ref={measureRef} // <--- Crucial for Dynamic Height!
70
70
  style={{
71
71
  position: 'absolute',
72
72
  top: 0,
73
73
  left: 0,
74
74
  width: '100%',
75
- height: itemHeight,
76
- transform: `translateY(${offsetTop}px)`, // Crucial for positioning
75
+ transform: `translateY(${offsetTop}px)`,
77
76
  display: 'flex',
78
77
  alignItems: 'center',
79
78
  paddingLeft: 10,
79
+ minHeight: 50, // Optional: just for visual
80
80
  background: index % 2 === 0 ? '#fff' : '#f5f5f5'
81
81
  }}
82
82
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-virtualize",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A lightweight, dependency-free virtualization hook for React.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",