Комментарии:
thanks it works
ОтветитьThankyou so much 😊
Ответить🌟 promo sm
ОтветитьThis seems entirely backwards for many reasons.
Async await doesn't return the value slower, it just waits until there is a value to return. Infact async await is a low level tool for solving the problem you describe, it tells the JavaScript engine "hey wait for this value to return before moving on". By itself async await is just a way to write async code and have it fit in with the synchronous code surrounding it thereby avoiding long promise .then chains.
Using the optional chaining operator for async values is a code smell and you are better off building in conditions for when your data isn't ready. Optional chaining is best used for optional values that every instance of an object might not have.
In your react example, your component has a few early returns which is good for catching issues like this. However it seems you are initializing user in context as an empty object hence needing the optional chaining operator, which means the second early return where you check !user will always return false as an empty object in js is not falsey
In pure clientside react the better way of approaching this is rendering a loading state (probably in the context provider component) until the async getUserFromDb function actually returns something and go from there
Why the hell are you trying to retrieve someone’s email? I’m confused
Ответить