@atlaskit/popup
Version:
A popup displays brief content in an overlay.
20 lines (19 loc) • 702 B
JavaScript
import React, { Fragment, useLayoutEffect, useRef } from 'react';
// eslint-disable-next-line @repo/internal/react/require-jsdoc
export const RepositionOnUpdate = ({
children,
update
}) => {
// Ref used here to skip update on first render (when refs haven't been set)
const isFirstRenderRef = useRef(true);
useLayoutEffect(() => {
if (isFirstRenderRef.current) {
isFirstRenderRef.current = false;
return;
}
// callback function from popper that repositions pop-up on content Update
update();
}, [update]);
// wrapping in fragment to make TS happy (known issue with FC returning children)
return /*#__PURE__*/React.createElement(Fragment, null, children);
};