In my react JS Code i have 2 Onclick function
class Traders extends Component {
constructor(props) {
super(props);
this.state = {
value: 10,
listVisibleList: false,
gridVisibleList: false,
listVisibleGrid: false,
gridVisibleGrid: false
};
}
componentDidMount() {
}
onClickListView() {
this.setState({
listVisibleList: !this.state.listVisibleList,
gridVisibleList: !this.state.gridVisibleList
});
}
onClickGridView(){
this.setState({
listVisibleGrid: !this.state.listVisibleGrid,
gridVisibleGrid: !this.state.gridVisibleGrid
});
}
render() {
const widthRisk = {
width: '60%'
};
return (
<div id="home">
<Col xs={12} sm={12} md={2}>
<div className="option-layout">
<ul>
<li>
<a href="#" onClick={() => this.onClickListView()}>
<img src="../../src/assets/images/list.png" className="img-respnsive" alt="list" />
</a>
</li>
<li>
<a href="#" onClick={() => this.onClickGridView()} >
<img src="../../src/assets/images/grid.png" className="img-respnsive" alt="grid" />
</a>
</li>
</ul>
</div>
</Col>
{
this.state.listVisibleList ? <ListTrader /> : <ListTrader />
}
{/* <ListTrader /> */}
{/* <GridTrader /> */}
</div>
)
}
The problem is how i want to show some specific component.
When i click onClickListView
it shows <ListTrader />
Component and <GridTrader />
Component hide
When i click onClickGridView
it shows <GridTrader />
Component and <ListTrader />
Component hide
I already tried to do some show and hide referring from this question
Show/Hide components in ReactJS
But the onClick from that question the function showing like toggle function. Any idea how to solve this?
Your help really appreciate. Thanks.