I have state like this -
state = {
modal: {
status: {
visible: true
}
}
};
and i tried this
handleShow = e => {
let newState = this.state.modal;
newState.status.visible = false;
this.setState({ modal: newState });
};
First time it makes true->false but i want toggle like(true to false and false to true) when i click.
Here is complete Sample code
class App extends React.Component {
state = {
modal: { status: { visible: true } }
};
handleShow = e => {
let newState = this.state.modal;
newState.status.visible = false;
this.setState({ modal: newState });
};
render() {
return (
<>
<div>
{this.state.modal.status.visible ? (
<div style={showStyle}>"it's showing"</div>
) : (
"It's Hidden"
)}
</div>
<button onClick={this.handleShow}>
{this.state.modal.status.visible ? "Hide" : "Show"}
</button>
</>
);
}
}
const showStyle={
backgroundColor: 'coral',
height: '100px'
}
Can anybody help me with this?. Thanks.