Skip to content

How to get updated data from localStorage / sync tabs? #1614

Answered by ShahriarKh
ShahriarKh asked this question in Q&A
Discussion options

You must be logged in to vote

Reading the docs again, I finally made it work:

const updateStore = () => {
    useStoreName.persist.rehydrate();
};

useEffect(() => {
    document.addEventListener("visibilitychange", updateStore);
    window.addEventListener("focus", updateStore);
    return () => {
        document.removeEventListener("visibilitychange", updateStore);
        window.removeEventListener("focus", updateStore);
    };
}, []);

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@jakehopking
Comment options

@semanticist21
Comment options

@mhsattarian
Comment options

@semanticist21
Comment options

@mhsattarian
Comment options

Answer selected by ShahriarKh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants