1
1
import * as _ from 'lodash'
2
- import * as PropTypes from 'prop-types'
3
2
import * as React from 'react'
4
3
import { Accordion , Menu , Sticky } from 'semantic-ui-react'
5
4
@@ -13,27 +12,29 @@ const sidebarStyle = {
13
12
paddingTop : '0.1em' ,
14
13
}
15
14
16
- class ComponentSidebar extends React . Component < any , any > {
17
- static propTypes = {
18
- activePath : PropTypes . string ,
19
- displayName : PropTypes . string ,
20
- examplesRef : PropTypes . object ,
21
- onItemClick : PropTypes . func ,
22
- }
15
+ type ComponentSidebarProps = {
16
+ activePath : string
17
+ displayName : string
18
+ examplesRef : HTMLElement
19
+ onItemClick : ( e : React . SyntheticEvent , { examplePath : string } ) => void
20
+ }
23
21
22
+ class ComponentSidebar extends React . Component < ComponentSidebarProps , any > {
24
23
state : any = { }
25
24
26
25
componentDidMount ( ) {
27
- this . fetchSections ( )
26
+ this . fetchSections ( this . props . displayName )
28
27
}
29
28
30
- componentWillReceiveProps ( nextProps ) {
31
- this . fetchSections ( nextProps )
29
+ componentDidUpdate ( prevProps : ComponentSidebarProps ) {
30
+ if ( this . props . displayName !== prevProps . displayName ) {
31
+ this . fetchSections ( this . props . displayName )
32
+ }
32
33
}
33
34
34
- fetchSections = ( { displayName } = this . props ) => {
35
+ fetchSections = ( displayName : string ) => {
35
36
import ( `docs/src/exampleMenus/${ displayName } .examples.json` ) . then ( sections => {
36
- this . setState ( { sections } )
37
+ this . setState ( { sections : sections . default } )
37
38
} )
38
39
}
39
40
0 commit comments