Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
5df91795
Unverified
Commit
5df91795
authored
Aug 20, 2024
by
tom goriunov
Committed by
GitHub
Aug 20, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2164 from blockscout/tom2drum/issue-2149
Cancel previous search queries when typing
parents
d1e52065
af2d6680
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
useApiQuery.tsx
lib/api/useApiQuery.tsx
+9
-5
No files found.
lib/api/useApiQuery.tsx
View file @
5df91795
import
type
{
QueryKey
,
UseQueryOptions
}
from
'
@tanstack/react-query
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
type
{
ResourceError
,
ResourceName
,
ResourcePayload
}
from
'
./resources
'
;
import
type
{
Params
as
ApiFetchParams
}
from
'
./useApiFetch
'
;
import
type
{
Params
as
FetchParams
}
from
'
lib/hooks/useFetch
'
;
import
type
{
ResourceError
,
ResourceName
,
ResourcePathParams
,
ResourcePayload
}
from
'
./resources
'
;
import
useApiFetch
from
'
./useApiFetch
'
;
export
interface
Params
<
R
extends
ResourceName
,
E
=
unknown
,
D
=
ResourcePayload
<
R
>>
extends
ApiFetchParams
<
R
>
{
export
interface
Params
<
R
extends
ResourceName
,
E
=
unknown
,
D
=
ResourcePayload
<
R
>>
{
pathParams
?:
ResourcePathParams
<
R
>
;
queryParams
?:
Record
<
string
,
string
|
Array
<
string
>
|
number
|
boolean
|
undefined
>
;
fetchParams
?:
Pick
<
FetchParams
,
'
body
'
|
'
method
'
|
'
headers
'
>
;
queryOptions
?:
Omit
<
UseQueryOptions
<
ResourcePayload
<
R
>
,
ResourceError
<
E
>
,
D
>
,
'
queryKey
'
|
'
queryFn
'
>
;
queryKey
?:
QueryKey
;
}
...
...
@@ -27,11 +31,11 @@ export default function useApiQuery<R extends ResourceName, E = unknown, D = Res
return
useQuery
<
ResourcePayload
<
R
>
,
ResourceError
<
E
>
,
D
>
({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey
:
queryKey
||
getResourceKey
(
resource
,
{
pathParams
,
queryParams
}),
queryFn
:
async
()
=>
{
queryFn
:
async
(
{
signal
}
)
=>
{
// all errors and error typing is handled by react-query
// so error response will never go to the data
// that's why we are safe here to do type conversion "as Promise<ResourcePayload<R>>"
return
apiFetch
(
resource
,
{
pathParams
,
queryParams
,
fetchParams
})
as
Promise
<
ResourcePayload
<
R
>>
;
return
apiFetch
(
resource
,
{
pathParams
,
queryParams
,
fetchParams
:
{
...
fetchParams
,
signal
}
})
as
Promise
<
ResourcePayload
<
R
>>
;
},
...
queryOptions
,
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment