Skip to content

Commit

Permalink
fix: offsetHeight null error (react-component#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
lift46252 committed Jul 4, 2024
1 parent cf2e973 commit 598fbd6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
6 changes: 2 additions & 4 deletions es/hooks/useHeights.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import * as React from 'react';
import { useRef, useEffect } from 'react';
import findDOMNode from "rc-util/es/Dom/findDOMNode";
import raf from "rc-util/es/raf";
import CacheMap from "../utils/CacheMap";
export default function useHeights(getKey, onItemAdd, onItemRemove) {
Expand All @@ -21,10 +20,9 @@ export default function useHeights(getKey, onItemAdd, onItemRemove) {
var doCollect = function doCollect() {
instanceRef.current.forEach(function (element, key) {
if (element && element.offsetParent) {
var htmlElement = findDOMNode(element);
var offsetHeight = htmlElement.offsetHeight;
var offsetHeight = element.offsetHeight;
if (heightsRef.current.get(key) !== offsetHeight) {
heightsRef.current.set(key, htmlElement.offsetHeight);
heightsRef.current.set(key, offsetHeight);
}
}
});
Expand Down
6 changes: 2 additions & 4 deletions lib/hooks/useHeights.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports.default = useHeights;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _findDOMNode = _interopRequireDefault(require("rc-util/lib/Dom/findDOMNode"));
var _raf = _interopRequireDefault(require("rc-util/lib/raf"));
var _CacheMap = _interopRequireDefault(require("../utils/CacheMap"));
function useHeights(getKey, onItemAdd, onItemRemove) {
Expand All @@ -29,10 +28,9 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
var doCollect = function doCollect() {
instanceRef.current.forEach(function (element, key) {
if (element && element.offsetParent) {
var htmlElement = (0, _findDOMNode.default)(element);
var offsetHeight = htmlElement.offsetHeight;
var offsetHeight = element.offsetHeight;
if (heightsRef.current.get(key) !== offsetHeight) {
heightsRef.current.set(key, htmlElement.offsetHeight);
heightsRef.current.set(key, offsetHeight);
}
}
});
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useHeights.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { useRef, useEffect } from 'react';
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import raf from 'rc-util/lib/raf';
import type { GetKey } from '../interface';
import CacheMap from '../utils/CacheMap';
Expand Down Expand Up @@ -30,10 +29,10 @@ 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 { offsetHeight } = element;

if (heightsRef.current.get(key) !== offsetHeight) {
heightsRef.current.set(key, htmlElement.offsetHeight);
heightsRef.current.set(key, offsetHeight);
}
}
});
Expand Down

0 comments on commit 598fbd6

Please sign in to comment.