File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
src/useDataApiHook-example Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -7,22 +7,22 @@ const useDataApi = (initialUrl, initialData) => {
7
7
const [ isLoading , setIsLoading ] = useState ( false ) ;
8
8
const [ isError , setIsError ] = useState ( false ) ;
9
9
10
- const fetchData = async ( ) => {
11
- setIsError ( false ) ;
12
- setIsLoading ( true ) ;
10
+ useEffect ( ( ) => {
11
+ const fetchData = async ( ) => {
12
+ setIsError ( false ) ;
13
+ setIsLoading ( true ) ;
13
14
14
- try {
15
- const result = await axios ( url ) ;
15
+ try {
16
+ const result = await axios ( url ) ;
16
17
17
- setData ( result . data ) ;
18
- } catch ( error ) {
19
- setIsError ( true ) ;
20
- }
18
+ setData ( result . data ) ;
19
+ } catch ( error ) {
20
+ setIsError ( true ) ;
21
+ }
21
22
22
- setIsLoading ( false ) ;
23
- } ;
23
+ setIsLoading ( false ) ;
24
+ } ;
24
25
25
- useEffect ( ( ) => {
26
26
fetchData ( ) ;
27
27
} , [ url ] ) ;
28
28
You can’t perform that action at this time.
0 commit comments