Skip to content

Commit

Permalink
fix: simplify debouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
mediremi committed Apr 2, 2021
1 parent 1c6d249 commit 8ddee00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2021-04-01T14:53:42.851Z\n"
"PO-Revision-Date: 2021-04-01T14:53:42.851Z\n"
"POT-Creation-Date: 2021-04-02T16:41:53.558Z\n"
"PO-Revision-Date: 2021-04-02T16:41:53.558Z\n"

msgid "App uninstalled successfully"
msgstr ""
Expand Down
16 changes: 5 additions & 11 deletions src/pages/AppHub/AppHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InputField, Pagination } from '@dhis2/ui'
import { NoticeBox, CenteredContent, CircularLoader } from '@dhis2/ui'
import React, { useEffect } from 'react'
import { useHistory } from 'react-router-dom'
import { useDebouncedCallback } from 'use-debounce'
import { useDebounce } from 'use-debounce'
import {
useQueryParams,
StringParam,
Expand Down Expand Up @@ -99,22 +99,16 @@ AppsList.propTypes = {

export const AppHub = () => {
const [queryParams, setQueryParams] = useQueryParams({
query: StringParam,
query: withDefault(StringParam, ''),
page: withDefault(NumberParam, 1),
})
const [debouncedQuery] = useDebounce(queryParams.query, 300)
const { loading, error, data, called, refetch } = useDataQuery(query, {
lazy: true,
})
const debouncedRefetch = useDebouncedCallback(
params => refetch(params),
300,
{
leading: true,
}
)
useEffect(() => {
debouncedRefetch(queryParams)
}, [queryParams.query, queryParams.page])
refetch(queryParams)
}, [debouncedQuery, queryParams.page])
const handleQueryChange = query => {
setQueryParams({ query, page: 1 }, 'replace')
}
Expand Down

0 comments on commit 8ddee00

Please sign in to comment.