-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make "download data" contents not "[]"/"undefined" (#89)
Currently the download link is randomly broken because when the `url.current` ref changes the `<a>` doesn't necessarily re-render. Using `setState` ensures that the `<a>` re-renders immediately when the data changes. This currently causes the behavior where the download link gives you a file containing the initial state of `data` (`[]` on the comparisons page, `undefined` on the bar plots) rather than the most up-to-date contents of `data` (which should be populated once data is successfully fetched).
- Loading branch information
Showing
3 changed files
with
25 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { useQuery } from "react-query" | ||
|
||
export function useFetch(url) { | ||
return useQuery( | ||
url, | ||
/* eslint-disable */ | ||
() => fetch(url).then((res) => res.json()), | ||
/* eslint-enable */ | ||
{ staleTime: Infinity } | ||
) | ||
return useQuery({ | ||
queryKey: url, | ||
queryFn: () => { | ||
if (url) { | ||
return fetch(url).then((res) => res.json()) | ||
} else { | ||
return [] | ||
} | ||
}, | ||
staleTime: Infinity, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters