11import * as React from 'react'
2- import { forwardRef , useRef , Ref , useCallback } from 'react'
2+ import { forwardRef , useRef , Ref , useCallback , useEffect } from 'react'
33import { useLayoutEffect } from 'react-layout-effect'
44import {
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