Skip to content

Commit 05d0e13

Browse files
authored
feat: remove ReactDom findDomNode (#295)
1 parent 1dfbbf8 commit 05d0e13

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ https://virtual-list-react-component.vercel.app/
2424
```bash
2525
npm install
2626
npm start
27-
open http://localhost:9001/
27+
open http://localhost:8000/
2828
```
2929

3030
## Feature

examples/basic.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ const Demo = () => {
7474
<button
7575
type="button"
7676
onClick={() => {
77-
listRef.current.scrollTo(null);
77+
listRef.current?.scrollTo(null);
7878
}}
7979
>
8080
Show scroll bar
8181
</button>
8282
<button
8383
type="button"
8484
onClick={() => {
85-
listRef.current.scrollTo(500);
85+
listRef.current?.scrollTo(500);
8686
}}
8787
>
8888
Scroll To 100px
8989
</button>
9090
<button
9191
type="button"
9292
onClick={() => {
93-
listRef.current.scrollTo({
93+
listRef.current?.scrollTo({
9494
index: 99999999,
9595
align: 'top',
9696
});
@@ -101,7 +101,7 @@ const Demo = () => {
101101
<button
102102
type="button"
103103
onClick={() => {
104-
listRef.current.scrollTo({
104+
listRef.current?.scrollTo({
105105
index: 50,
106106
align: 'top',
107107
});
@@ -112,7 +112,7 @@ const Demo = () => {
112112
<button
113113
type="button"
114114
onClick={() => {
115-
listRef.current.scrollTo({
115+
listRef.current?.scrollTo({
116116
index: 50,
117117
align: 'bottom',
118118
});
@@ -123,7 +123,7 @@ const Demo = () => {
123123
<button
124124
type="button"
125125
onClick={() => {
126-
listRef.current.scrollTo({
126+
listRef.current?.scrollTo({
127127
index: 50,
128128
align: 'auto',
129129
});
@@ -134,7 +134,7 @@ const Demo = () => {
134134
<button
135135
type="button"
136136
onClick={() => {
137-
listRef.current.scrollTo({
137+
listRef.current?.scrollTo({
138138
index: 50,
139139
align: 'top',
140140
offset: 15,
@@ -146,7 +146,7 @@ const Demo = () => {
146146
<button
147147
type="button"
148148
onClick={() => {
149-
listRef.current.scrollTo({
149+
listRef.current?.scrollTo({
150150
index: 50,
151151
align: 'bottom',
152152
offset: 15,
@@ -158,7 +158,7 @@ const Demo = () => {
158158
<button
159159
type="button"
160160
onClick={() => {
161-
listRef.current.scrollTo({
161+
listRef.current?.scrollTo({
162162
key: 50,
163163
align: 'auto',
164164
});
@@ -179,7 +179,7 @@ const Demo = () => {
179179
<button
180180
type="button"
181181
onClick={() => {
182-
listRef.current.scrollTo({
182+
listRef.current?.scrollTo({
183183
index: data.length - 2,
184184
align: 'top',
185185
});
@@ -190,7 +190,7 @@ const Demo = () => {
190190
<button
191191
type="button"
192192
onClick={() => {
193-
listRef.current.scrollTo({
193+
listRef.current?.scrollTo({
194194
index: 0,
195195
align: 'bottom',
196196
});
@@ -202,7 +202,7 @@ const Demo = () => {
202202
<button
203203
type="button"
204204
onClick={() => {
205-
listRef.current.scrollTo({
205+
listRef.current?.scrollTo({
206206
index: 50,
207207
align: 'top',
208208
});

src/hooks/useHeights.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
21
import * as React from 'react';
32
import { useEffect, useRef } from 'react';
43
import type { GetKey } from '../interface';
@@ -37,9 +36,8 @@ export default function useHeights<T>(
3736

3837
instanceRef.current.forEach((element, key) => {
3938
if (element && element.offsetParent) {
40-
const htmlElement = findDOMNode<HTMLElement>(element);
41-
const { offsetHeight } = htmlElement;
42-
const { marginTop, marginBottom } = getComputedStyle(htmlElement);
39+
const { offsetHeight } = element;
40+
const { marginTop, marginBottom } = getComputedStyle(element);
4341

4442
const marginTopNum = parseNumber(marginTop);
4543
const marginBottomNum = parseNumber(marginBottom);

0 commit comments

Comments
 (0)