@particle-academy/react-fancy 3.4.2 → 3.4.3

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.
package/dist/index.cjs CHANGED
@@ -3265,21 +3265,21 @@ function useFloatingPosition(anchorRef, floatingRef, options = {}) {
3265
3265
  if (!anchor || !floating) return;
3266
3266
  const anchorRect = anchor.getBoundingClientRect();
3267
3267
  const floatingRect = floating.getBoundingClientRect();
3268
- setPosition(getPosition(anchorRect, floatingRect, placement, offset));
3268
+ const next = getPosition(anchorRect, floatingRect, placement, offset);
3269
+ setPosition(
3270
+ (prev) => prev.x === next.x && prev.y === next.y && prev.placement === next.placement ? prev : next
3271
+ );
3269
3272
  }, [anchorRef, floatingRef, placement, offset]);
3270
- react.useLayoutEffect(() => {
3271
- if (!enabled) return;
3272
- let raf = 0;
3273
- let frames = 0;
3274
- const measure = () => {
3275
- update();
3276
- if (!floatingRef.current && frames++ < 20) {
3277
- raf = requestAnimationFrame(measure);
3278
- }
3279
- };
3280
- measure();
3281
- return () => cancelAnimationFrame(raf);
3282
- }, [update, enabled, floatingRef]);
3273
+ react.useEffect(() => {
3274
+ if (enabled) update();
3275
+ });
3276
+ react.useEffect(() => {
3277
+ if (!enabled) {
3278
+ setPosition(
3279
+ (prev) => prev.x === -9999 ? prev : { x: -9999, y: -9999, placement }
3280
+ );
3281
+ }
3282
+ }, [enabled, placement]);
3283
3283
  react.useEffect(() => {
3284
3284
  if (!enabled) return;
3285
3285
  window.addEventListener("scroll", update, true);