Skip to content

Commit 5a352cf

Browse files
committed
docs: getRootElement
1 parent d1b0ef2 commit 5a352cf

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ interface VirtualListHandle {
109109
index: number,
110110
block?: "start" | "end" | "center" | "nearest"
111111
): void;
112+
getRootElement(): HTMLElement;
112113
forceUpdate(): void;
113114
}
114115
```
115116

116117
Then use the `ref` object to access the exposed methods.
117118

118119
- `scrollToIndex`: `(index:number, block = 'start'):void`. Scroll to the specified index position. `block` is equal to the `block` option of the HTML native method `scrollIntoView`.
120+
- `getRootElement`: Get list HTML element。
119121
- `forceUpdate`: Forcefully re-render the list. This can be called after the visible area of the list changes.
120122

121123
## Note

README_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ interface VirtualListHandle {
109109
index: number,
110110
block?: "start" | "end" | "center" | "nearest"
111111
): void;
112+
getRootElement(): HTMLElement;
112113
forceUpdate(): void;
113114
}
114115
```
115116

116117
然后使用获取到的`ref`对象操作暴露的方法。
117118

118119
- `scrollToIndex`: `(index:number, block = 'start'):void`. 滚动到指定索引位置。`block`等于 HTML 原生方法`scrollIntoView``block`选项。
120+
- `getRootElement`: 获取列表 HTML 元素。
119121
- `forceUpdate`: 强制重新渲染列表。可以再列表可见区域变换后调用此方法。
120122

121123
## 注意

lib/VirtualList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export const defaultProps = {
6363

6464
export interface VirtualListHandle {
6565
scrollToIndex(index: number, block?: 'start' | 'end' | 'center' | 'nearest'): void
66-
forceUpdate(): void
6766
getRootElement(): HTMLElement
67+
forceUpdate(): void
6868
}
6969

7070
export const VirtualList = forwardRef(function <ITEM>(
@@ -188,12 +188,12 @@ export const VirtualList = forwardRef(function <ITEM>(
188188
prevScrollTop.current = scrollTop
189189
setShouldScrollToIndex([]) // ensure re-render but exclude itemSize. setForceRerender will re calculate avg itemSize, so don't use it here.
190190
},
191-
forceUpdate() {
192-
setForceRerender([])
193-
},
194191
getRootElement() {
195192
return list.current!
196193
},
194+
forceUpdate() {
195+
setForceRerender([])
196+
},
197197
}), [itemSize]);
198198
// scrollToIndex
199199
useLayoutEffect(() => {

0 commit comments

Comments
 (0)