Skip to content

Commit

Permalink
fix(query): bug recreated QueryUrl instead memoized
Browse files Browse the repository at this point in the history
  • Loading branch information
chornos13 committed Dec 27, 2020
1 parent 1b2a72e commit 730ecfa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/helpers/QueryUrl/useUrlQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import QueryUrl, { QueryUrlOptions } from 'helpers/QueryUrl/QueryUrl'
import { useMemo, useState } from 'react'
import { useMemo, useRef, useState } from 'react'
import queryString from 'query-string'

export type UseUrlQueryOptions = {} & QueryUrlOptions

function useUrlQuery(_options?: UseUrlQueryOptions) {
const { ...queryUrlOptions } = { ..._options }

const queryUrl = new QueryUrl(queryUrlOptions)
const refQueryUrl = useRef(new QueryUrl(queryUrlOptions))
const queryUrl = refQueryUrl.current
const [filtered, setFiltered] = useState(queryUrl.filtered.toArrayStringify())
const [sorted, setSorted] = useState(queryUrl.sorted.toArrayStringify())
const [localQuery, setLocalQuery] = useState(queryUrl.query.get())
Expand Down

0 comments on commit 730ecfa

Please sign in to comment.