我注意到,在編寫React組件時,我的三元表達式正在打破30-40%的時間。我不確定是否有一條規則,他們不能進入某個特定的地方或發生了什麼,因爲語法看起來對我有效。錯誤信息要麼沒有幫助,要麼我只是缺少明顯的東西。無法在React組件中編譯三元表達式
class AuthContainer extends Component {
render() {
const { errorMessage, handleLogin, handleLogout, isAuthenticated } = this.props
return (
{ isAuthenticated
? <Logout onLogoutClick={() => handleLogout()} />
: <Login
errorMessage={errorMessage}
onLoginClick={(e) => handleLogin(e)}
/>
}
)
}
}
isAuthenticated
是一個布爾
啊。這可以解釋爲什麼它有時會起作用,有時它會像這樣打破。我需要更多地關注上下文。刪除'{'的作品。謝謝! – tim5046