Hey guys! an NGRX question
I have in my state "configurations feature selector" which is always populated with data when the user logs in,
but when my user logs out we get alot of console errors from the selectors "cannot read properties of null (reading features)".
the initial state is null and when populated it has alot of inner objects.
It seems abit weird to add to every selector a check if the state exists then return it, else return null or {}. ( I have about 50+ selectors) because the data is always there. except for after logout.
Hopefully somebody have a cleaner way to handle this?
Thanks!
#Ngrx Selectors
5 messages · Page 1 of 1 (latest)
Humm. Hey there !
It’s hard to get the idea of what’s going with such description but if I got it right, doesn’t the problem reside in some components that is still showing up and calling those selectors while you may only show it if you are logged in ? When you log out you should destroy any components in the UI that would make use of user data. Or I m really not on it ?
can you perhaps share a more complete stack trace of what’s going on ?
@hallow bloom Hey sun thanks for your response,
After the user clicks on logout I clear all the state and redirect to the login page.
But the problem might be that the state is cleared and the selectors are trying to emit one more time before the components that are using those selectors are destroyed.
The main problem is that this configurations state always has data, so it makes no sense for me to check in the selectors if state exists return it else return null,
Hence the errors are showing in the console.