Skip to content

Commit

Permalink
refactor: change memoization of margins to support the rule of hooks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jun 14, 2024
1 parent 2736835 commit fbf90ec
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ export const RegionsWithIntersections = forwardRef(function RegionsWithIntersect
props: RegionsWithIntersectionsProps,
ref: ForwardedRef<HTMLDivElement>,
) {
const {regions, render, children, margins: marginsProp} = props
const {
regions,
render,
children,
margins: [mt, mr, mb, ml],
} = props

const overlayRef = useRef<HTMLDivElement | null>(null)

// Make sure `margins` is memoized
// eslint-disable-next-line react-hooks/exhaustive-deps
const margins = useMemo(() => marginsProp, [JSON.stringify(marginsProp)])
const margins = useMemo<[number, number, number, number]>(
() => [mt, mr, mb, ml],
[mt, mr, mb, ml],
)

const io = useMemo(
() =>
Expand Down

0 comments on commit fbf90ec

Please sign in to comment.