Skip to content

Commit c58159c

Browse files
authored
Finish feature/112
2 parents 70ce09c + 56f080b commit c58159c

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/hooks/js/useFetch.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { useState, useEffect, useRef } from 'react';
1+
import { useState, useEffect } from 'react';
22

33
export 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();

src/hooks/ts/useFetch.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
44
interface 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();

0 commit comments

Comments
 (0)