Question : Cannot read properties of null (reading 'isAdmin') useSelector
Answered by : alien0w0
You should make your code safe.
For modern js you could use the optional chaining operator
const admin = useSelector((state) => state.user?.currentUser?.isAdmin)
A more traditional approach to do the same thing
const admin = useSelector((state) => state.user && state.user.currentUser && state.user.currentUser.isAdmin)
Source : | Last Update : Wed, 13 Jul 22