Skip to content

Commit

Permalink
feat: add custom hook
Browse files Browse the repository at this point in the history
  • Loading branch information
moonbamijam committed Jan 22, 2024
1 parent 46a1814 commit f75c536
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hooks/useFetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Url } from "next/dist/shared/lib/router/router"

export const useFetch = async (url: Url) => {
try {
const response = await fetch(`${ url }`, {
cache: 'no-store',
})

if(!response.ok) {
throw new Error("Failed fetching!")
}
return response.json()
} catch (error) {
console.log("Error occured: ", error)
}
}

0 comments on commit f75c536

Please sign in to comment.