FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
edge-react-gui/src/hooks/useAsyncValue.ts at develop · EdgeApp/edge-react-gui · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
EdgeApp
/
edge-react-gui
Public
Notifications
You must be signed in to change notification settings
Fork
293
Star
519
Code
Issues
51
Pull requests
144
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
edge-react-gui
/
src
/
hooks
/
useAsyncValue.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (34 loc) · 899 Bytes
Breadcrumbs
edge-react-gui
/
src
/
hooks
/
useAsyncValue.ts
Copy path
File metadata and controls
38 lines (34 loc) · 899 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import
*
as
React
from
'react'
import
{
useAsyncEffect
}
from
'./useAsyncEffect'
/**
* Returns the value of an async function or an error.
* Re-runs when its dependencies change, just like `useAsyncEffect`.
*/
export
function
useAsyncValue
<
T
>
(
effect
:
(
)
=>
Promise
<
T
>
,
deps
?:
unknown
[
]
)
:
[
T
|
undefined
,
Error
|
undefined
]
{
const
[
value
,
setValue
]
=
React
.
useState
<
T
|
undefined
>
(
undefined
)
const
[
error
,
setError
]
=
React
.
useState
<
Error
|
undefined
>
(
undefined
)
let
cancel
=
false
useAsyncEffect
(
async
(
)
=>
{
try
{
const
value
=
await
effect
(
)
if
(
cancel
)
return
setValue
(
value
)
setError
(
undefined
)
}
catch
(
error
:
any
)
{
if
(
cancel
)
return
setValue
(
undefined
)
setError
(
error
)
}
return
(
)
=>
{
cancel
=
true
}
}
,
deps
,
'useAsyncValue'
)
return
[
value
,
error
]
}
Back
|
FazBrowse Home
|
New Git URL