Tell us what’s happening:
My code does not pass the test.
It works at console.
Please help me.
Your code so far
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
visibility: false
};
// Ändere den Code unterhalb dieser Zeile
this.toggleVisibility = this.toggleVisibility.bind(this);
// Ändere den Code oberhalb dieser Zeile
}
// Ändere den Code unterhalb dieser Zeile
toggleVisibility() {
this.setState(state => ({
visibility: !state.visibility
}));
}
// Ändere den Code oberhalb dieser Zeile
render() {
if (this.state.visibility) {
return (
<div>
<button onClick={this.toggleVisibility}>Click Me</button>
<h1>Now you see me!</h1>
</div>
);
} else {
return (
<div>
<button onClick={this.toggleVisibility}>Click Me</button>
</div>
);
}
}
}
Your browser information:
User Agent ist: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
React - Verwende den Zustand um ein Element umzuschalten