File tree Expand file tree Collapse file tree 2 files changed +4
-14
lines changed
Expand file tree Collapse file tree 2 files changed +4
-14
lines changed Original file line number Diff line number Diff line change 1- import { useState , useEffect , useRef } from 'react' ;
1+ import { useState , useEffect } from 'react' ;
22
33export const useFetch = ( url , reqOpt ) => {
44 const [ data , setData ] = useState ( ) ;
55 const [ error , setError ] = useState ( ) ;
66 const [ isLoading , setIsLoading ] = useState ( false ) ;
77 const [ isSuccess , setIsSuccess ] = useState ( false ) ;
8- const effectRan = useRef ( false ) ;
98
109 const fetchData = async ( ) => {
1110 setIsLoading ( true ) ;
@@ -35,11 +34,7 @@ export const useFetch = (url, reqOpt) => {
3534 } ;
3635
3736 useEffect ( ( ) => {
38- ! effectRan . current && fetchData ( ) ;
39-
40- return ( ) => {
41- effectRan . current = true ;
42- } ;
37+ fetchData ( ) ;
4338 } , [ ] ) ;
4439
4540 const refetch = ( ) => fetchData ( ) ;
Original file line number Diff line number Diff line change 1- import { useState , useEffect , useRef } from 'react' ;
1+ import { useState , useEffect } from 'react' ;
22
33// Define the interface for the data returned by the API.
44interface Data { }
@@ -11,7 +11,6 @@ export const useFetch = (url: string, reqOpt?: RequestInit) => {
1111 const [ error , setError ] = useState < Error > ( ) ;
1212 const [ isLoading , setIsLoading ] = useState ( false ) ;
1313 const [ isSuccess , setIsSuccess ] = useState ( false ) ;
14- const effectRan = useRef ( false ) ;
1514
1615 const fetchData = async ( ) => {
1716 setIsLoading ( true ) ;
@@ -41,11 +40,7 @@ export const useFetch = (url: string, reqOpt?: RequestInit) => {
4140 } ;
4241
4342 useEffect ( ( ) => {
44- ! effectRan . current && fetchData ( ) ;
45-
46- return ( ) => {
47- effectRan . current = true ;
48- } ;
43+ fetchData ( ) ;
4944 } , [ ] ) ;
5045
5146 const refetch = ( ) => fetchData ( ) ;
You can’t perform that action at this time.
0 commit comments