@dhis2-ui/intersection-detector 10.11.0 → 10.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,8 @@ const IntersectionDetector = _ref => {
32
32
  // @var {Object}
33
33
  // @prop {HTMLElement} current
34
34
  const intersectionRef = (0, _react.useRef)();
35
+ const onChangeRef = (0, _react.useRef)(onChange);
36
+ onChangeRef.current = onChange;
35
37
  (0, _react.useEffect)(() => {
36
38
  const rootEl = rootRef.current;
37
39
  const intersectionEl = intersectionRef.current;
@@ -46,7 +48,7 @@ const IntersectionDetector = _ref => {
46
48
  const intersectionChange = entry.isIntersecting !== isIntersecting.current;
47
49
  if (intersectionChange) {
48
50
  isIntersecting.current = entry.isIntersecting;
49
- onChange({
51
+ onChangeRef.current({
50
52
  isIntersecting: entry.isIntersecting
51
53
  });
52
54
  }
@@ -63,7 +65,7 @@ const IntersectionDetector = _ref => {
63
65
  // the disconnect function for better readability.
64
66
  return () => intersectionObserver.disconnect();
65
67
  }
66
- }, [rootRef.current, intersectionRef.current]);
68
+ }, [rootRef, threshold]);
67
69
  return /*#__PURE__*/_react.default.createElement("div", {
68
70
  ref: intersectionRef,
69
71
  "data-test": dataTest,
@@ -23,6 +23,8 @@ export const IntersectionDetector = _ref => {
23
23
  // @var {Object}
24
24
  // @prop {HTMLElement} current
25
25
  const intersectionRef = useRef();
26
+ const onChangeRef = useRef(onChange);
27
+ onChangeRef.current = onChange;
26
28
  useEffect(() => {
27
29
  const rootEl = rootRef.current;
28
30
  const intersectionEl = intersectionRef.current;
@@ -37,7 +39,7 @@ export const IntersectionDetector = _ref => {
37
39
  const intersectionChange = entry.isIntersecting !== isIntersecting.current;
38
40
  if (intersectionChange) {
39
41
  isIntersecting.current = entry.isIntersecting;
40
- onChange({
42
+ onChangeRef.current({
41
43
  isIntersecting: entry.isIntersecting
42
44
  });
43
45
  }
@@ -54,7 +56,7 @@ export const IntersectionDetector = _ref => {
54
56
  // the disconnect function for better readability.
55
57
  return () => intersectionObserver.disconnect();
56
58
  }
57
- }, [rootRef.current, intersectionRef.current]);
59
+ }, [rootRef, threshold]);
58
60
  return /*#__PURE__*/React.createElement("div", {
59
61
  ref: intersectionRef,
60
62
  "data-test": dataTest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/intersection-detector",
3
- "version": "10.11.0",
3
+ "version": "10.12.0",
4
4
  "description": "UI IntersectionDetector",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2/ui-constants": "10.11.0",
36
+ "@dhis2/ui-constants": "10.12.0",
37
37
  "classnames": "^2.3.1",
38
38
  "prop-types": "^15.7.2"
39
39
  },