Skip to content

Commit

Permalink
fix(reactive-react): fix react18 strict mode dispose trigger timing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jun 26, 2022
1 parent 505db59 commit 9182e1f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/reactive-react/src/hooks/useObserver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Tracker } from '@formily/reactive'
import { GarbageCollector } from '../shared'
import { GarbageCollector, immediate } from '../shared'
import { IObserverOptions } from '../types'
import { useForceUpdate } from './useForceUpdate'

Expand Down Expand Up @@ -46,10 +46,12 @@ export const useObserver = <T extends () => any>(
gcRef.current.close()
return () => {
unMountRef.current = true
if (trackerRef.current) {
trackerRef.current.dispose()
trackerRef.current = null
}
immediate(() => {
if (trackerRef.current && unMountRef.current) {
trackerRef.current.dispose()
trackerRef.current = null
}
})
}
}, [])

Expand Down

0 comments on commit 9182e1f

Please sign in to comment.