(callback: () => void)
| 265 | return { |
| 266 | positionRef, |
| 267 | preventLayoutShift(callback: () => void) { |
| 268 | if (!positionRef.current) { |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | let initialTop = positionRef.current.getBoundingClientRect().top; |
| 273 | |
| 274 | callback(); |
| 275 | |
| 276 | rafRef.current = window.requestAnimationFrame(() => { |
| 277 | let newTop = |
| 278 | positionRef.current?.getBoundingClientRect().top ?? |
| 279 | initialTop; |
| 280 | window.scrollBy(0, newTop - initialTop); |
| 281 | }); |
| 282 | } |
| 283 | }; |
| 284 | } |
| 285 |