Skip to content

Commit

Permalink
utils like fetcher URL etc
Browse files Browse the repository at this point in the history
  • Loading branch information
sohhamm committed Dec 31, 2021
1 parent be6a829 commit 34cfe17
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_APP_URL="http://localhost:9000/api/cats"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
dist
dist-ssr
*.local
.env
.env
.production
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react-router-dom": "^6.2.1"
},
"devDependencies": {
"@types/node": "^17.0.5",
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@vitejs/plugin-react": "^1.0.7",
Expand Down
4 changes: 4 additions & 0 deletions src/components/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const images = [
export default function Hero() {
const [searchText, setSearchText] = React.useState('')

React.useEffect(() => {
if (!searchText.length) return
}, [searchText])

return (
<main className="font-brand">
<div className="rounded-t-[42px] w-100% lg:bg-hero-lg md:bg-hero-md sm:bg-hero-sm h-auto object-contain border-current mt-10 pb-32 pt-4">
Expand Down
5 changes: 5 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type FetcherType = (
url: string,
method: string,
payload: object,
) => Promise<any>
20 changes: 20 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {FetcherType} from '../types'

export const URL = import.meta.env.VITE_APP_URL

export const fetcher: FetcherType = async (url, method = 'GET', payload) => {
try {
const data = await (
await fetch(url, {
method,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
).json()
return data
} catch (err) {
console.error(err)
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@
"@svgr/hast-util-to-babel-ast" "^6.0.0"
svg-parser "^2.0.2"

"@types/node@^17.0.5":
version "17.0.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.5.tgz#57ca67ec4e57ad9e4ef5a6bab48a15387a1c83e0"
integrity sha512-w3mrvNXLeDYV1GKTZorGJQivK6XLCoGwpnyJFbJVK/aTBQUxOCaa/GlFAAN3OTDFcb7h5tiFG+YXCO2By+riZw==

"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
Expand Down

0 comments on commit 34cfe17

Please sign in to comment.