Type Error: Cannot Read Properties of Null

Type Error: Cannot Read Properties of Null

10,244 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

I.......
I....... - 27.10.2023 11:17

thanks it works

Ответить
Rahul kumar
Rahul kumar - 20.07.2023 15:02

Thankyou so much 😊

Ответить
Ivan
Ivan - 09.04.2023 17:51

🌟 promo sm

Ответить
Diamond Jo
Diamond Jo - 01.02.2023 10:38

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

Ответить
More Kiwi & Gaming (MMS)
More Kiwi & Gaming (MMS) - 01.02.2023 10:11

Why the hell are you trying to retrieve someone’s email? I’m confused

Ответить