@particle-academy/react-fancy 3.4.1 → 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,16 +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
- update();
3273
- const raf = requestAnimationFrame(() => {
3274
- update();
3275
- });
3276
- return () => cancelAnimationFrame(raf);
3277
- }, [update, enabled]);
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]);
3278
3283
  react.useEffect(() => {
3279
3284
  if (!enabled) return;
3280
3285
  window.addEventListener("scroll", update, true);