-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDP-949] State refactor: countries (#42)
* State refactor: countries * Keep fetched data for a bit longer * Fix stale time
- Loading branch information
Showing
7 changed files
with
29 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { API_URL } from "constants/settings"; | ||
import { fetchApi } from "helpers/fetchApi"; | ||
import { ApiCountry, AppError } from "types"; | ||
|
||
export const useCountries = () => { | ||
const query = useQuery<ApiCountry[], AppError>({ | ||
queryKey: ["countries"], | ||
queryFn: async () => { | ||
return await fetchApi(`${API_URL}/countries`); | ||
}, | ||
// Keeping the fetched data for longer since it won't change that often | ||
staleTime: 5 * 60 * 1000, | ||
}); | ||
|
||
return query; | ||
}; |
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 was deleted.
Oops, something went wrong.
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