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.
↧
Handling non null assertions in react native application
↧