Skip to content

Commit c454ce4

Browse files
committed
fix: scrollTop is not set when from & to are equal pmndrs#1185
1 parent e8b1e19 commit c454ce4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/animated/src/withAnimated.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { forwardRef, useRef, Ref, useCallback } from 'react'
2+
import { forwardRef, useRef, Ref, useCallback, useEffect } from 'react'
33
import { useLayoutEffect } from 'react-layout-effect'
44
import {
55
is,
@@ -44,7 +44,8 @@ export const withAnimated = (Component: any, host: HostConfig) => {
4444
const [props, deps] = getAnimatedState(givenProps, host)
4545

4646
const forceUpdate = useForceUpdate()
47-
const observer = new PropsObserver(() => {
47+
48+
const callback = () => {
4849
const instance = instanceRef.current
4950
if (hasInstance && !instance) {
5051
// Either this component was unmounted before changes could be
@@ -60,7 +61,9 @@ export const withAnimated = (Component: any, host: HostConfig) => {
6061
if (didUpdate === false) {
6162
forceUpdate()
6263
}
63-
}, deps)
64+
}
65+
66+
const observer = new PropsObserver(callback, deps)
6467

6568
const observerRef = useRef<PropsObserver>()
6669
useLayoutEffect(() => {
@@ -77,6 +80,7 @@ export const withAnimated = (Component: any, host: HostConfig) => {
7780
}
7881
})
7982

83+
useEffect(callback, [])
8084
// Stop observing on unmount.
8185
useOnce(() => () => {
8286
const observer = observerRef.current!

0 commit comments

Comments
 (0)