Passed
Push — master ( cfe6bd...bdceca )
by Guangyu
04:33 queued 12s
created

src/hooks/useFakeFetch.js   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 23
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 20
mnd 1
bc 1
fnc 0
dl 0
loc 23
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import { useEffect, useState } from 'react';
2
3
const useFakeFetch = (resolvedData, waitingTime = 500) => {
4
  const [loading, setLoading] = useState(true);
5
  const [data, setData] = useState([]);
6
7
  useEffect(() => {
8
    let isMounted = true;
9
    setTimeout(() => {
10
      if (isMounted) {
11
        setData(resolvedData);
12
        setLoading(false);
13
      }
14
    }, waitingTime);
15
16
    return () => (isMounted = false);
17
  }, [resolvedData, waitingTime]);
18
19
  return { loading, setLoading, data, setData };
20
};
21
22
export default useFakeFetch;
23