-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user counties): Add get counties hook to pull user state counties (
#762) * working through api logic * figuring out logic to call get counties * add get county logic to user context * Update states.ts * Update user.ts * clean up logic * Update userContext.tsx * Update userContext.tsx * Update userContext.tsx * Update userContext.tsx * Update userContext.tsx * add optional chain * add feedback to apiCall logic * Update SlotField.tsx * wrap in try catch * adjust array name * add bens feedback * Update useGetUser.ts * Update user.ts
- Loading branch information
Showing
7 changed files
with
176 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
const fetchPopulationData = async (stateString: string) => { | ||
try { | ||
if (stateString) { | ||
const response = await fetch( | ||
`https://api.census.gov/data/2019/pep/population?get=NAME&for=county:*&in=state:${stateString}`, | ||
); | ||
if (!response.ok) { | ||
throw new Error("Failed to fetch county data"); | ||
} | ||
|
||
const data = await response.json(); | ||
return data.slice(1).map((item) => item[0]); | ||
} | ||
return []; | ||
} catch (error) { | ||
console.error("Error fetching county data:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const usePopulationData = (stateString: string) => { | ||
return useQuery( | ||
["populationData", stateString], | ||
() => fetchPopulationData(stateString), | ||
{ | ||
refetchOnWindowFocus: false, | ||
refetchOnReconnect: false, | ||
refetchOnMount: false, | ||
}, | ||
); | ||
}; | ||
|
||
export default usePopulationData; |
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
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