I've used reactstrap Tabs in the map function. When I change the tab, all the Tabs are changed. This is because, when I change the state on click, the state is changed for all the Tabs.
I've also tried with a similar problem, but I was failed.
https://stackblitz.com/edit/react-puqfqg?file=index.js
Here is my code:
import jsonData from './customData.json';
class ClassName extends Component {
constructor(props) {
super();
this.state = {
activeTab: '1'
};
this.toggle = this.toggle.bind(this);
}
toggle(tab) {
if (this.state.activeTab !== tab) {
this.setState({
activeTab: tab
});
}
}
render() {
return (
<div>
{
jsonData.map((data, index) => (
<Nav tabs>
<NavItem>
<NavLink className={({active: this.state.activeTab === '1'})} onClick={() => {this.toggle('1');}}>
Tab 1</NavLink>
</NavItem>
<NavItem>
<NavLink className={({active: this.state.activeTab === '2'})} onClick={() => {this.toggle('2');}}>
Tab 2</NavLink>
</NavItem>
</Nav>
<TabContent activeTab={this.state.activeTab}>
<TabPane tabId="1">
{data.description}
</TabPane>
<TabPane tabId="2">
{data.image}
</TabPane>
</TabContent>
))
}
</div>
)
}
}
export default ClassName;