#Ngrx Selectors

5 messages · Page 1 of 1 (latest)

unkempt sun
#

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!

hallow bloom
#

can you perhaps share a more complete stack trace of what’s going on ?

unkempt sun
#

@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.