Skip to content

Works across tabs, but not within a single tab #3

@raiskila

Description

@raiskila

Hi,

While the storage event is fired when another page modifies local storage, it's not fired when the current page modifies local storage. Thus two components on the same page using this hook won't stay in sync. Demo codesandbox

The setState function should probably also be wrapped in useCallback to prevent its reference identity from changing on every render. This is consistent with the setter returned by useState and the dispatch function returned by useReducer, and allows for things like passing the function down in React context without causing components downstream to update constantly.

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