Skip to content
This repository was archived by the owner on Dec 3, 2022. It is now read-only.
This repository was archived by the owner on Dec 3, 2022. It is now read-only.

useFocusEffect should not retrigger on re-render #48

@slorber

Description

@slorber

Reported by in https://github.com/react-navigation/hooks/pull/43/files#r334335721 by @ArrayZoneYour

The following code is likely to produce an infinite loop, even if we make sure the dependency is stable using a ref, because useFocusEffect use "navigation" as a dependency and the object is unstable.

useFocusEffect(useCallback(() => { 
  setParamsRef.current({});
},[setParamsRef])); 

The focus effect might retrigger unnecessarily due to the navigation being unstable

Somehow this is related to #40

@satya164 what do you think about using a useNavigationRef hook as you suggested in some other issue? Didn't get a clear answer from the React team on how to handle this kind of situation but that should work. Or maybe I should depend only on isFocused and addListener which are the only 2 fn used, but if core does not guarantee stability across render the problem remains.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions