Skip to content

Commit

Permalink
fix: Optimize useFetch to reduce redraws
Browse files Browse the repository at this point in the history
  • Loading branch information
baumandm committed Mar 21, 2023
1 parent e9037af commit 4139dc4
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/frontend/src/shared/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useState, useEffect } from 'react';

interface Props {
url: string;
contents?: string | null | undefined;
contents?: string | undefined;
method?: 'GET' | 'HEAD';
paused?: boolean;
}
Expand All @@ -35,7 +35,7 @@ interface Props {
*/
export const useFetch = ({ url, contents, method = 'GET', paused = false }: Props) => {
const [fetching, setFetching] = useState(false);
const [data, setData] = useState<string | undefined>(undefined);
const [data, setData] = useState<string | undefined>(contents);
const [error, setError] = useState<any>(undefined);

useEffect(() => {
Expand All @@ -49,7 +49,6 @@ export const useFetch = ({ url, contents, method = 'GET', paused = false }: Prop

// Already pre-fetched? Let's use it!
if (contents != null) {
setData(contents);
return;
}

Expand Down

0 comments on commit 4139dc4

Please # to comment.