Skip to content

Commit aa80a38

Browse files
committed
fixes #3 check for ref before accessing current
1 parent d936193 commit aa80a38

File tree

3 files changed

+10074
-22
lines changed

3 files changed

+10074
-22
lines changed

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-smart-scroll",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Smart Scroll React Component for long lists",
55
"author": "Steven Sacks",
66
"homepage": "https://github.com/stevensacks/react-smart-scroll",
@@ -44,25 +44,25 @@
4444
},
4545
"dependencies": {},
4646
"peerDependencies": {
47-
"react": "^16.8.0"
47+
"react": "^16.12.0"
4848
},
4949
"devDependencies": {
5050
"babel-eslint": "^10.0.3",
51-
"eslint": "^6.5.1",
52-
"eslint-config-prettier": "^6.4.0",
53-
"eslint-config-react-app": "^5.0.2",
54-
"eslint-plugin-flowtype": "^4.3.0",
55-
"eslint-plugin-import": "^2.18.2",
51+
"eslint": "^6.8.0",
52+
"eslint-config-prettier": "^6.9.0",
53+
"eslint-config-react-app": "^5.1.0",
54+
"eslint-plugin-flowtype": "^4.5.3",
55+
"eslint-plugin-import": "^2.19.1",
5656
"eslint-plugin-jsx-a11y": "^6.2.3",
57-
"eslint-plugin-prettier": "^3.1.1",
58-
"eslint-plugin-react": "^7.16.0",
59-
"eslint-plugin-react-hooks": "^2.1.2",
60-
"husky": "^3.0.9",
61-
"lint-staged": "^9.4.2",
57+
"eslint-plugin-prettier": "^3.1.2",
58+
"eslint-plugin-react": "^7.17.0",
59+
"eslint-plugin-react-hooks": "^2.3.0",
60+
"husky": "^4.0.3",
61+
"lint-staged": "^9.5.0",
6262
"nwb": "0.23.x",
63-
"prettier": "^1.18.2",
63+
"prettier": "^1.19.1",
6464
"prop-types": "^15.7.2",
6565
"react": "^16.10.2",
66-
"react-dom": "^16.10.2"
66+
"react-dom": "^16.12.0"
6767
}
6868
}

src/hooks/useComponentRect.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import {useEffect, useState} from 'react';
33
export default ref => {
44
const [rect, setRect] = useState({});
55
useEffect(() => {
6-
const {current} = ref;
7-
const onResize = () => {
8-
setRect(current.getBoundingClientRect());
9-
};
10-
if (current) {
11-
window.addEventListener('resize', onResize);
12-
setRect(current.getBoundingClientRect());
6+
if (ref) {
7+
const {current} = ref;
8+
const onResize = () => {
9+
setRect(current.getBoundingClientRect());
10+
};
11+
if (current) {
12+
window.addEventListener('resize', onResize);
13+
setRect(current.getBoundingClientRect());
14+
}
15+
return () => window.removeEventListener('resize', onResize);
1316
}
14-
return () => window.removeEventListener('resize', onResize);
1517
}, [ref]);
1618
return rect;
1719
};

0 commit comments

Comments
 (0)