Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

Handling non null assertions in react native application

$
0
0

I have authContext in my react native application with a token property, it can be string | null.
I have some protected routes, meaning I'm not showing links unless user is logged in and token exists.
On this routes I'm trying to use this token, but TypeScript saying it could be null, which makes sense, but I know that it couldn't.
I know I can use non assertion operator token!, but is there an alternative to this problem because it's happening very often often in my code and seems there should be a better way to approach this problem. Appreciate any thoughts on this, thanks.


Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>