Tell us what’s happening:
can someone explain to me what this means below:-
.
Currently, there is no way of updating the visibility property in the component’s state . The value should toggle back and forth between true and false. There is a click handler on the button which triggers a class method called toggleVisibility() . Pass a function to setState to define this method so that the state of visibility toggles to the opposite value when the method is called. If visibility is false , the method sets it to true , and vice versa.
**Your code so far**
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
visibility: false
};
// Change code below this line
this.setState(state => ({
toggleVisibility: state.toggleVisibility + false
}))
// Change code above this line
}
// Change code below this line
// 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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Use State to Toggle an Element
Link to the challenge: