-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathApp.js
49 lines (41 loc) · 1.15 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import {Tabs, TabContent} from './tabs.js';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
activeTabIndex: this.getActiveTabIndexFromHash() || 0,
};
}
getActiveTabIndexFromHash() {
if (!window.location.hash)
return 0;
try {
let index = window.location.hash.split('-')[0].split('#')[1];
if (isNaN(index))
index = 0;
else
index = Number(index);
return index;
} catch (error) {
return 0;
}
}
onTabClick = (index, slug) => {
window.location.hash = index + '-' + slug;
this.setState({activeTabIndex: index});
}
render() {
return (
<div className="playground">
<Tabs
activeTabIndex={this.state.activeTabIndex}
onClick={this.onTabClick}
/>
<TabContent
activeTabIndex={this.state.activeTabIndex}
/>
</div>
);
}
}