Skip to content

Commit 95fc582

Browse files
committed
componentWillReceiveProps -> componentDidUpdate
1 parent d2b263a commit 95fc582

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
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

src/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33
import { ApolloProvider } from 'react-apollo'
44
import { BrowserRouter } from 'react-router-dom'
5-
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles'
65

76
import './index.css'
87
import registerServiceWorker from './registerServiceWorker'
98
import App from './components/App'
109
import { apollo } from './lib/apollo'
1110

12-
const GRAPHQL_PINK = '#e10098'
13-
14-
const theme = createMuiTheme({
15-
palette: { primary: { main: GRAPHQL_PINK } }
16-
})
17-
1811
ReactDOM.render(
1912
<BrowserRouter>
2013
<ApolloProvider client={apollo}>
21-
<MuiThemeProvider theme={theme}>
22-
<App />
23-
</MuiThemeProvider>
14+
<App />
2415
</ApolloProvider>
2516
</BrowserRouter>,
2617
document.getElementById('root')

src/lib/withUser.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ export const USER_QUERY = gql`
1010
email
1111
photo
1212
hasPurchased
13-
favoriteReviews {
14-
id
15-
}
1613
}
1714
}
1815
`

0 commit comments

Comments
 (0)