Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ https://virtual-list-react-component.vercel.app/
```bash
npm install
npm start
open http://localhost:9001/
open http://localhost:8000/
```

## Feature
Expand Down
24 changes: 12 additions & 12 deletions examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo(null);
listRef.current?.scrollTo(null);
}}
>
Show scroll bar
</button>
<button
type="button"
onClick={() => {
listRef.current.scrollTo(500);
listRef.current?.scrollTo(500);
}}
>
Scroll To 100px
</button>
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 99999999,
align: 'top',
});
Expand All @@ -101,7 +101,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 50,
align: 'top',
});
Expand All @@ -112,7 +112,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 50,
align: 'bottom',
});
Expand All @@ -123,7 +123,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 50,
align: 'auto',
});
Expand All @@ -134,7 +134,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 50,
align: 'top',
offset: 15,
Expand All @@ -146,7 +146,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 50,
align: 'bottom',
offset: 15,
Expand All @@ -158,7 +158,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
key: 50,
align: 'auto',
});
Expand All @@ -179,7 +179,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: data.length - 2,
align: 'top',
});
Expand All @@ -190,7 +190,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 0,
align: 'bottom',
});
Expand All @@ -202,7 +202,7 @@ const Demo = () => {
<button
type="button"
onClick={() => {
listRef.current.scrollTo({
listRef.current?.scrollTo({
index: 50,
align: 'top',
});
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useHeights.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import * as React from 'react';
import { useEffect, useRef } from 'react';
import type { GetKey } from '../interface';
Expand Down Expand Up @@ -35,9 +34,8 @@ export default function useHeights<T>(
const doCollect = () => {
instanceRef.current.forEach((element, key) => {
if (element && element.offsetParent) {
const htmlElement = findDOMNode<HTMLElement>(element);
const { offsetHeight } = htmlElement;
const { marginTop, marginBottom } = getComputedStyle(htmlElement);
const { offsetHeight } = element;
const { marginTop, marginBottom } = getComputedStyle(element);

const marginTopNum = parseNumber(marginTop);
const marginBottomNum = parseNumber(marginBottom);
Expand Down