File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,24 @@ class ListNote extends Component {
8
8
super ( ) ;
9
9
this . state = { active : - 1 } ;
10
10
}
11
- componentDidMount ( ) {
12
- const { location } = this . props ;
11
+ _getActiveFromURL ( props ) {
12
+ const { location } = props ;
13
13
const regex = / \/ n o t e s \/ ( [ 0 - 9 ] + ) (?: \/ e d i t | $ ) / ;
14
14
const active = location . pathname . match ( regex ) ;
15
+ return active ? Number ( active [ 1 ] ) : null ;
16
+ }
17
+ componentDidMount ( ) {
18
+ const active = this . _getActiveFromURL ( this . props ) ;
15
19
if ( active ) {
16
- this . setState ( { active : Number ( active [ 1 ] ) } ) ;
20
+ this . setState ( { active } ) ;
17
21
}
18
22
}
23
+ componentWillReceiveProps ( nextProps ) {
24
+ const active = this . _getActiveFromURL ( nextProps ) ;
25
+ if ( active && active !== this . state . active ) {
26
+ this . setState ( { active } ) ;
27
+ }
28
+ }
19
29
render ( ) {
20
30
const { list } = this . props ;
21
31
const { active } = this . state ;
You can’t perform that action at this time.
0 commit comments