'UseStore is async? How to ensure that store-data is loaded completely?

I have a serious problem with State Management in React. I am using Zustand and it works pretty well.

However, when I access the store and try to output it one the console, for example:

const USER = useStore(state => state.currentUser) 
console.log(USER)

the result logged is null. If the page rerenders it is the correct userobject.

The store is set up as follows:

import react from "react";
import create from "zustand";

const useStore = create(set => ({

    currentUser: null
}))

export default useStore

Thus, I suppose that useStore works asynchronously, i.e. updates the variable with the pages next render. Is that correct? So, how can I ensure that the store variables are loaded completely, before I continue?

Hope, the problem is clear to everyone?

Thanks in advance,

Wiwi



Solution 1:[1]

Right answer (in the comments!). Used an async Func for the user data. That solved the riddle for me! Thanks!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 WiWi