Tell us what’s happening:
Your code so far
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
visibility: false
};
// change code below this line
this.toggleVisibility = this.toggleVisibility.bind(this);
}
// change code below this line
toggleVisibility() {
this.setstate(state => ({
visibility: !state.visibility
}));
}
// change code above this line
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 is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Use State to Toggle an Element
Link to the challenge:
When I write the code myself I get errors but if I paste the code of solution 2(which is the same from where I’m standing)
toggleVisibility() {
this.setstate(state => ({
visibility: !state.visibility
}));
}
it compiles and the test goes throught.
What I am not getting ?!?