beginner in React and javascript, i'm stuck to this problem:
How can i show/hide a specific div when i click to his dedicated shutter button?
here is the idea i came with but as you may see , when i click an "open" or " close " link, it justs affect every div.
import React from 'react'
class Qui extends React.Component {
constructor(props) {
super(props);
this.state = { isToggleOn: true };
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState(prevState => ({
isToggleOn: !prevState.isToggleOn
}));
}
render() {
return(
<div>
<h1>first part</h1>
<a onClick={this.handleClick>
{this.state.isToggleOn ? 'open' : 'close'}
</a>
<div className={this.state.isToggleOn ? 'hidden':'visible'}>
<p> blablabla blablabla </p>
<p> blablabla blablabla </p>
<p> blablabla blablabla </p>
</div>
<h1>second part</h1>
<a onClick={this.handleClick>
{this.state.isToggleOn ? 'open' : 'close'}
</a>
<div className={this.state.isToggleOn ? 'hidden':'visible'}>
<p> onetwothree onetwothree </p>
<p> onetwothree onetwothree </p>
<p> onetwothree onetwothree </p>
</div>
</div>
)
}
}
Thanks for helping me :) .