Skip to content

Commit

Permalink
fix: scrollTop is not set when from & to are equal pmndrs#1185
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohanhacker committed Mar 21, 2021
1 parent e8b1e19 commit c454ce4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/animated/src/withAnimated.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { forwardRef, useRef, Ref, useCallback } from 'react'
import { forwardRef, useRef, Ref, useCallback, useEffect } from 'react'
import { useLayoutEffect } from 'react-layout-effect'
import {
is,
Expand Down Expand Up @@ -44,7 +44,8 @@ export const withAnimated = (Component: any, host: HostConfig) => {
const [props, deps] = getAnimatedState(givenProps, host)

const forceUpdate = useForceUpdate()
const observer = new PropsObserver(() => {

const callback = () => {
const instance = instanceRef.current
if (hasInstance && !instance) {
// Either this component was unmounted before changes could be
Expand All @@ -60,7 +61,9 @@ export const withAnimated = (Component: any, host: HostConfig) => {
if (didUpdate === false) {
forceUpdate()
}
}, deps)
}

const observer = new PropsObserver(callback, deps)

const observerRef = useRef<PropsObserver>()
useLayoutEffect(() => {
Expand All @@ -77,6 +80,7 @@ export const withAnimated = (Component: any, host: HostConfig) => {
}
})

useEffect(callback, [])
// Stop observing on unmount.
useOnce(() => () => {
const observer = observerRef.current!
Expand Down

0 comments on commit c454ce4

Please sign in to comment.