MCPcopy
hub / github.com/react-native-community/upgrade-helper / useFetchDiff

Function useFetchDiff

src/hooks/fetch-diff.ts:18–59  ·  view source on GitHub ↗
({
  shouldShowDiff,
  packageName,
  language,
  fromVersion,
  toVersion,
}: UseFetchDiffProps)

Source from the content-addressed store, hash-verified

16 toVersion: string
17}
18export const useFetchDiff = ({
19 shouldShowDiff,
20 packageName,
21 language,
22 fromVersion,
23 toVersion,
24}: UseFetchDiffProps) => {
25 const [isLoading, setIsLoading] = useState<boolean>(true)
26 const [isDone, setIsDone] = useState<boolean>(false)
27 const [diff, setDiff] = useState<File[]>([])
28
29 useEffect(() => {
30 const fetchDiff = async () => {
31 setIsLoading(true)
32 setIsDone(false)
33
34 const [response] = await Promise.all([
35 fetch(getDiffURL({ packageName, language, fromVersion, toVersion })),
36 delay(300),
37 ])
38
39 const diff = await response.text()
40
41 setDiff(movePackageJsonToTop(parseDiff(diff)))
42
43 setIsLoading(false)
44 setIsDone(true)
45
46 return
47 }
48
49 if (shouldShowDiff) {
50 fetchDiff()
51 }
52 }, [shouldShowDiff, packageName, language, fromVersion, toVersion])
53
54 return {
55 isLoading,
56 isDone,
57 diff,
58 }
59}

Callers 1

DiffViewerFunction · 0.90

Calls 1

fetchDiffFunction · 0.85

Tested by

no test coverage detected