Skip to content

Commit d0bd643

Browse files
🚑 fix crash when trying to see the history of a question (#392)
This pr fix a crash when trying to access the history of a question because the container was still using react-router v4 props and not react-router v6 hooks
1 parent 51b3c6b commit d0bd643

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

client/src/scenes/Question/scenes/Random/Random.container.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import { query } from 'services/apollo'
66
import { GET_RANDOM } from './queries'
77

88
import Random from './Random'
9+
import { useParams } from 'react-router'
910

1011
export default compose(
1112
query(GET_RANDOM, {
12-
variables: (props) => ({
13-
tag: props.match.params.tag,
14-
}),
13+
variables: () => {
14+
const params = useParams()
15+
return {
16+
tag: params.tag,
17+
}
18+
},
1519
fetchPolicy: 'network-only',
1620
}),
1721
withLoading(getIntl(Random)('loading')),

client/src/scenes/Question/scenes/Read/components/History/HistoryActions.container.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import { query } from 'services/apollo'
66
import { LOAD_HISTORY } from './queries'
77

88
import HistoryActions from './HistoryActions'
9+
import { useLocation, useParams } from 'react-router'
910

1011
const ENTRIES_PER_PAGE = 10
1112

1213
export default compose(
1314
query(LOAD_HISTORY, {
14-
variables: (props) => {
15-
const { page } = unserialize(props.location.search)
15+
variables: () => {
16+
const location = useLocation()
17+
const params = useParams()
18+
const { page } = unserialize(location.search)
1619
return {
17-
nodeId: routing.getUIDFromSlug(props.match),
20+
nodeId: routing.getUIDFromSlug(params),
1821
first: ENTRIES_PER_PAGE,
1922
skip: ENTRIES_PER_PAGE * (page - 1),
2023
}

client/src/services/routing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const routing = {
1515
history.push(arg)
1616
}
1717
},
18-
getUIDFromSlug(match) {
19-
return match.params.slug.split('-').pop()
18+
getUIDFromSlug(params) {
19+
return params.slug.split('-').pop()
2020
},
2121
getShareUrl(UID) {
2222
return `${window.location.origin}/q/${UID}`

0 commit comments

Comments
 (0)