File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -9,22 +9,28 @@ import get from 'lodash/get'
9
9
import { deslugify } from '../lib/helpers'
10
10
11
11
class Section extends Component {
12
- lastSectionId = null
13
-
14
- componentWillReceiveProps ( props ) {
15
- if ( ! props . section ) {
12
+ viewedSection = id => {
13
+ if ( ! id ) {
16
14
return
17
15
}
18
16
19
- const sectionChanged = props . section . id !== this . lastSectionId
17
+ setTimeout ( ( ) => {
18
+ this . props . viewedSection ( {
19
+ variables : { id }
20
+ } )
21
+ } , 2000 )
22
+ }
23
+
24
+ componentDidMount ( ) {
25
+ this . viewedSection ( get ( this , 'props.section.id' ) )
26
+ }
27
+
28
+ componentDidUpdate ( prevProps ) {
29
+ const { id } = this . props . section
30
+ const sectionChanged = get ( prevProps , 'section.id' ) !== id
20
31
21
32
if ( sectionChanged ) {
22
- setTimeout ( ( ) => {
23
- props . viewedSection ( {
24
- variables : { id : props . section . id }
25
- } )
26
- } , 2000 )
27
- this . lastSectionId = props . section . id
33
+ this . viewedSection ( id )
28
34
}
29
35
}
30
36
You can’t perform that action at this time.
0 commit comments