Hi all !
Just a quick question , hope someone is willing to help
when I click the ‘toggle display’ button , the text ‘Displayed!’ appears-reappears , so it seems to work, yet it doesn’t seem to be correct as it doesn’t pass. Any idea what could be the reason?
Thanks
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
display: true
}
this.toggleDisplay = this.toggleDisplay.bind(this);
}
toggleDisplay() {
this.setState({
display: !this.state.display
});
}
render() {
let hide={}
if(this.state.display){
hide={display:"block"}
}else {
hide={display:"none"}
}
return (
<div>
<button onClick={this.toggleDisplay}>Toggle Display</button>
<h1 style={hide}>Displayed!</h1>
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Render with an If-Else Condition
Link to the challenge: