Skip to content

Commit

Permalink
fix(intersection detector): remove observer state variabe and condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 committed Sep 15, 2020
1 parent 768d0be commit 3fc4637
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
12 changes: 5 additions & 7 deletions packages/core/src/IntersectionDetector/IntersectionDetector.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const IntersectionDetector = ({
onChange,
children,
className,
dataTest,
rootRef,
}) => {
// Use useRef instead of useState to prevent unnecessary re-render:
Expand All @@ -21,10 +22,6 @@ export const IntersectionDetector = ({
// heavy) children. Also: If the parent re-renders (e. g. due to a state
// change), then this component will re-render as well.

// @var {Object}
// @prop {IntersectionObserver} current
const observer = useRef()

// @var {Object}
// @prop {bool} current
const isIntersecting = useRef()
Expand All @@ -37,7 +34,7 @@ export const IntersectionDetector = ({
const rootEl = rootRef.current
const intersectionEl = intersectionRef.current

if (rootEl && intersectionEl && !observer.current) {
if (rootEl && intersectionEl) {
const onIntersection = entries => {
// Currently there's no way to supply multiple thresholds,
// so a single entry can be assumed safely
Expand All @@ -63,7 +60,6 @@ export const IntersectionDetector = ({
)

intersectionObserver.observe(intersectionEl)
observer.current = intersectionObserver

// Make sure to clean up everything when un-mounting.
// Using an arrow function instead of just returning
Expand All @@ -73,7 +69,7 @@ export const IntersectionDetector = ({
}, [rootRef.current, intersectionRef.current])

return (
<div ref={intersectionRef} className={className}>
<div ref={intersectionRef} className={className} data-test={dataTest}>
{children}

<style jsx>{`
Expand All @@ -90,6 +86,7 @@ export const IntersectionDetector = ({

IntersectionDetector.defaultProps = {
threshold: 0,
dataTest: 'dhis2-uicore-intersectiondetector',
}

/**
Expand All @@ -112,5 +109,6 @@ IntersectionDetector.propTypes = {

children: PropTypes.any,
className: PropTypes.string,
dataTest: PropTypes.string,
threshold: PropTypes.number,
}
1 change: 0 additions & 1 deletion packages/widgets/src/Transfer/OptionsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const OptionsContainer = ({
}) => {
const optionsRef = useRef(null)
const wrapperRef = useRef(null)

const resizeCounter = useResizeCounter(wrapperRef.current)

return (
Expand Down

0 comments on commit 3fc4637

Please sign in to comment.