Answer the question
In order to leave comments, you need to log in
Why is the event listener not hung up?
Good afternoon!
There is this piece of code. Checks if the user is authorized or not. If authorized, then display Dashboard. The Dashboard has a Navbar with a button that opens a modal window. But there is a problem - the modal window does not open, for some reason the listener is not hung up. If you remove the conditional statements and display only the Dashboard, then everything works fine. I use this example
function App() {
const {verifyAuthentication} = useActions()
const authData = useTypedSelector(state => state.auth)
const [status, setStatus] = useState('no')
const [auth, setAuth] = useState(false)
if (localStorage.getItem('token') && !auth) {
verifyAuthentication()
setAuth(true) // todo fix
}
useEffect(() => {
if (authData.loading && !authData.authResponse) setStatus('loading')
if (!authData.loading && authData.authResponse?.user) setStatus('yes')
if (!authData.loading && !authData.authResponse) setStatus('no')
}, [authData])
if (status === 'loading') return <FullWindowSpinner/>
if (status === 'yes') return <Dashboard/>
if (status === 'no') return <Authentication/>
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question