Skip to content

Infinite re-rendering with hook #285

Open
@dawsonc623

Description

@dawsonc623

Current behavior

I assume this behaviour is due to the functions coming back being new instances each time, but if I use the functions returned from the hook in a useEffect and add them to the dependency array, the useEffect fires infinitely. I can solve this by either not including them in the dependency array (not good practice) or wrapping them in a useCallback (not extraordinarily elegant, but better than the first option).

Expected behavior

The functions returned from the hook should be able to be placed in a dependency array of a useEffect without issue.

Repro steps

  1. Grab the getItem function (for example) from the hook.
  2. Create a useEffect hook that uses getItem.
  3. Do something obvious in the effect that will signal each time it is called (such as a console.warn).
  4. Add getItem to the dependency array of the useEffect.
  5. Run the code.

Environment

  • Async Storage version: ^1.7.1
  • React-Native version: 0.59.5
  • Platform tested: Android
  • Logs/Error that are relevant: N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions