UseInteractionManager clean up on component Unmount
nitishmyn opened this issue · 3 comments
nitishmyn commented
With reference to the documentation of https://reactnative.dev/docs/interactionmanager
The method runAfterInteractions
returns a cancellable promise, which has a cancel method, was wondering if this cancel method should be applied on component clean up.
https://github.com/react-native-community/hooks/blob/master/src/useInteractionManager.ts#L8
import {useEffect, useState, useRef} from 'react'
import {InteractionManager} from 'react-native'
export function useInteractionManager() {
const [complete, updateInteractionStatus] = useState(false)
const interactionHandler = useRef();
useEffect(() => {
interactionHandler.current = InteractionManager.runAfterInteractions(() => {
updateInteractionStatus(true)
})
return () => interactionHandler.current & interactionHandler.current.cancel()
}, [interactionHandler])
return complete
}
LinusU commented
Sound like a good idea!
Although I don't think that the code that you posted works? It needs to return something to the function inside useEffect
, not the runAfterInteractions
function.
What do you think about the approaching #310? It's the same as in the example code in the documentation you linked
nitish24p commented
LinusU commented
Merged 👍