【发布时间】:2021-11-08 06:41:06
【问题描述】:
我需要帮助理解 prevstate。我读过what is prevstate、reac-prevstate 和state and lifecycle。但我还是不明白。
export default function SignInUp(props) {
const [toggleClass, setToggleClass] = useState(false)
const { handleLogin, handleRegister } = props
const toggleState = () => {
setToggleClass(!prevState)
}
return (
<div className='UserContainer' style={{display: "grid", justifyContent: "center ", height: "100vh", width: "100vw"}}>
<div className='btncontainer' style={{gridRow: "2 / 3"}}>
<button onClick={toggleState} className='togglebtn' style={{background: "none", border: "none"}}>Signin</button>
<button onClick={toggleState} className='togglebtn' style={{background: "none", border: "none"}}>Signup</button>
</div>
<SignIn handleLogin={handleLogin} className={toggleClass ? 'Disabled' : null} style={{gridRow: "2 / 3" }}/>
<SignUp handleRegister={handleRegister} className={toggleClass ? 'Disabled' : null}/>
</div>
)
}
【问题讨论】: