Skip to content

Commit 6d91fa1

Browse files
committed
componentWillReceiveProps -> componentDidUpdate
1 parent 1d41eee commit 6d91fa1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/components/Section.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,28 @@ import get from 'lodash/get'
99
import { deslugify } from '../lib/helpers'
1010

1111
class Section extends Component {
12-
lastSectionId = null
13-
14-
componentWillReceiveProps(props) {
15-
if (!props.section) {
12+
viewedSection = id => {
13+
if (!id) {
1614
return
1715
}
1816

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
2031

2132
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)
2834
}
2935
}
3036

0 commit comments

Comments
 (0)