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) => {
77 const [ isLoading , setIsLoading ] = useState ( false ) ;
88 const [ isError , setIsError ] = useState ( false ) ;
99
10- const fetchData = async ( ) => {
11- setIsError ( false ) ;
12- setIsLoading ( true ) ;
10+ useEffect ( ( ) => {
11+ const fetchData = async ( ) => {
12+ setIsError ( false ) ;
13+ setIsLoading ( true ) ;
1314
14- try {
15- const result = await axios ( url ) ;
15+ try {
16+ const result = await axios ( url ) ;
1617
17- setData ( result . data ) ;
18- } catch ( error ) {
19- setIsError ( true ) ;
20- }
18+ setData ( result . data ) ;
19+ } catch ( error ) {
20+ setIsError ( true ) ;
21+ }
2122
22- setIsLoading ( false ) ;
23- } ;
23+ setIsLoading ( false ) ;
24+ } ;
2425
25- useEffect ( ( ) => {
2626 fetchData ( ) ;
2727 } , [ url ] ) ;
2828
You can’t perform that action at this time.
0 commit comments