bring over code challenge
This commit is contained in:
commit
76b596da09
20 changed files with 51221 additions and 0 deletions
16
hooks/use-api-data.ts
Normal file
16
hooks/use-api-data.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import axios from "axios"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export const useApiData = <T>(path: string, defaultValue: any): T => {
|
||||
const [ data, setData ] = useState<T>(defaultValue)
|
||||
|
||||
useEffect(() => {
|
||||
axios.get<T>(path).catch(err => err.response).then(response => {
|
||||
setData(response.data)
|
||||
})
|
||||
}, [])
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export default useApiData
|
Loading…
Add table
Add a link
Reference in a new issue