File tree 2 files changed +43
-1
lines changed
2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ Here are some of the snippets you can use:
56
56
For detailed information about each hook, check out the following links:
57
57
58
58
- [ useFetch Documentation] ( https://github.com/itszeeshan/react-custom-hooks/docs/useFetch.md )
59
- - [ useAsync Documentation] ( https://github.com/your-username /react-custom-hooks/docs/useAsync.md )
59
+ - [ useAsync Documentation] ( https://github.com/itszeeshan /react-custom-hooks/docs/useAsync.md )
60
60
61
61
## Contributing
62
62
Original file line number Diff line number Diff line change
1
+ ### ` useAsync `
2
+
3
+ A hook to handle asynchronous tasks.
4
+
5
+ ## Parameters
6
+
7
+ - ` callback ` (` function ` ): The asynchronous function to execute.
8
+ - ` dependencies ` (` array ` , optional): Dependency array to control when the async function should be executed.
9
+
10
+ ## Returns
11
+
12
+ - An object containing ` data ` , ` error ` , and ` loading ` .
13
+
14
+ ## Hooks Involved
15
+ - [ useState] ( https://react.dev/reference/react/useState )
16
+ - [ useCallback] ( https://react.dev/reference/react/useCallback )
17
+ - [ useEffect] ( https://react.dev/reference/react/useEffect )
18
+
19
+ ## How to Use
20
+
21
+ ``` js
22
+ import useAsync from " ./useAsync"
23
+
24
+ export default function AsyncComponent () {
25
+ const { loading , error , value } = useAsync (() => {
26
+ return new Promise ((resolve , reject ) => {
27
+ const success = false
28
+ setTimeout (() => {
29
+ success ? resolve (" Hi" ) : reject (" Error" )
30
+ }, 1000 )
31
+ })
32
+ })
33
+
34
+ return (
35
+ < div>
36
+ < div> Loading: {loading .toString ()}< / div>
37
+ < div> {error}< / div>
38
+ < div> {value}< / div>
39
+ < / div>
40
+ )
41
+ }
42
+ ```
You can’t perform that action at this time.
0 commit comments