Skip to content

Commit

Permalink
Use useNavigate instead of useHistory
Browse files Browse the repository at this point in the history
This was a breaking change
  • Loading branch information
flicken committed Jan 9, 2022
1 parent 555606d commit 1d641ef
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Agenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Filter from "./components/Filter"

import produce from "immer"

import { useLocation, useHistory } from "react-router-dom"
import { useLocation, useNavigate } from "react-router-dom"

import debounce from 'lodash.debounce'

Expand Down Expand Up @@ -84,13 +84,13 @@ const Row = ({day, filters, events, ...rest}) => {
</tr>
}

const updateSearchInURL = debounce((history, location, columns) => {
const updateSearchInURL = debounce((navigate, location, columns) => {
const search = new URLSearchParams()
columns.filter(c => c).forEach(c => search.append("filter", c))
const state = {...location, search: "?" + search.toString()}
if (state.search !== location.search &&
location.pathname === history.location.pathname) {
history.push(state)
location.pathname === navigate.location.pathname) {
navigate.push(state)
}
}, 250)

Expand All @@ -104,10 +104,10 @@ function Agenda(props, state) {
const location = useLocation()
const search = new URLSearchParams(location.search)
const [columns, setColumns] = useState(search.getAll('filter'))
const history = useHistory()
const navigate = useNavigate()

React.useEffect(() => {
const unlisten = history.listen((newLocation, action) => {
const unlisten = navigate.listen((newLocation, action) => {
if (newLocation.pathname !== location.pathname) {
updateSearchInURL.cancel()
}
Expand All @@ -120,8 +120,8 @@ function Agenda(props, state) {
}, []) // eslint-disable-line react-hooks/exhaustive-deps

React.useEffect(() => {
updateSearchInURL(history, location, columns)
}, [history, location, columns])
updateSearchInURL(navigate, location, columns)
}, [navigate, location, columns])

let dom = nextDays(new DateTime({}), 40).map(d => d.toISODate())

Expand Down

0 comments on commit 1d641ef

Please sign in to comment.