如何在 Context.Consumer 中使用“if”语句?我需要检查context.state.showLoginBox是否为真,然后显示下面的 div。
class LogInBox extends Component {
render() {
return(
<MyContext.Consumer>
{(context) => (// context.state.showLoginBox ? => show div below
<div className="logInBoxWrapper" id="logInBoxId">
<div className="logInBox">
<h3>Войти</h3>
<form method="">
<input name="email" placeholder="Электронная почта" required/>
<input name="password" type="password" placeholder="Пароль" required/>
<button type="submit">Войти</button>
</form>
</div>
</div>
)}
</MyContext.Consumer>
);
}
}