React 抱怨下面的代码,说它 useEffect 被有条件地调用:
import React, { useEffect, useState } from 'react'
import VerifiedUserOutlined from '@material-ui/icons/VerifiedUserOutlined'
import withStyles from '@material-ui/core/styles/withStyles'
import firebase from '../firebase'
import { withRouter } from 'react-router-dom'
function Dashboard(props) {
  const { classes } = props
  
  const [quote, setQuote] = useState('')
    if(!firebase.getCurrentUsername()) {
        // not logged in
        alert('Please login first')
        props.history.replace('/login')
        return null
    }
    useEffect(() => {
        firebase.getCurrentUserQuote().then(setQuote)
    })
    return (
        <main>
            // some code here
        </main>
    )
    async function logout() {
        await firebase.logout()
        props.history.push('/')
    }
}
export default withRouter(withStyles(styles)(Dashboard))
这让我返回错误:
React Hook "useEffect" 被有条件地调用。在每个组件渲染中,必须以完全相同的顺序调用 React Hook。
有谁碰巧知道这里的问题是什么?