diff --git a/next.config.mjs b/next.config.mjs
index d5456a1..692255a 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -1,6 +1,15 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
- reactStrictMode: true,
+ reactStrictMode: true,
+ images: {
+ remotePatterns: [
+ {
+ protocol: 'https',
+ hostname: 'cdn.dummyjson.com',
+ pathname: '/**',
+ },
+ ],
+ },
};
export default nextConfig;
diff --git a/package-lock.json b/package-lock.json
index b41dd18..a3434ed 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,9 +8,11 @@
"name": "practice-next-page",
"version": "0.1.0",
"dependencies": {
+ "@tanstack/react-query": "^5.40.0",
"next": "14.2.3",
"react": "^18",
- "react-dom": "^18"
+ "react-dom": "^18",
+ "react-hook-form": "^7.51.5"
},
"devDependencies": {
"@types/node": "^20",
@@ -442,6 +444,30 @@
"tslib": "^2.4.0"
}
},
+ "node_modules/@tanstack/query-core": {
+ "version": "5.40.0",
+ "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.40.0.tgz",
+ "integrity": "sha512-eD8K8jsOIq0Z5u/QbvOmfvKKE/XC39jA7yv4hgpl/1SRiU+J8QCIwgM/mEHuunQsL87dcvnHqSVLmf9pD4CiaA==",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/tannerlinsley"
+ }
+ },
+ "node_modules/@tanstack/react-query": {
+ "version": "5.40.0",
+ "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.40.0.tgz",
+ "integrity": "sha512-iv/W0Axc4aXhFzkrByToE1JQqayxTPNotCoSCnarR/A1vDIHaoKpg7FTIfP3Ev2mbKn1yrxq0ZKYUdLEJxs6Tg==",
+ "dependencies": {
+ "@tanstack/query-core": "5.40.0"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/tannerlinsley"
+ },
+ "peerDependencies": {
+ "react": "^18.0.0"
+ }
+ },
"node_modules/@types/json5": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
@@ -3719,6 +3745,21 @@
"react": "^18.3.1"
}
},
+ "node_modules/react-hook-form": {
+ "version": "7.51.5",
+ "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.51.5.tgz",
+ "integrity": "sha512-J2ILT5gWx1XUIJRETiA7M19iXHlG74+6O3KApzvqB/w8S5NQR7AbU8HVZrMALdmDgWpRPYiZJl0zx8Z4L2mP6Q==",
+ "engines": {
+ "node": ">=12.22.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/react-hook-form"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17 || ^18"
+ }
+ },
"node_modules/react-is": {
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
diff --git a/package.json b/package.json
index fac6906..9a4cfa0 100644
--- a/package.json
+++ b/package.json
@@ -9,18 +9,20 @@
"lint": "next lint"
},
"dependencies": {
+ "@tanstack/react-query": "^5.40.0",
+ "next": "14.2.3",
"react": "^18",
"react-dom": "^18",
- "next": "14.2.3"
+ "react-hook-form": "^7.51.5"
},
"devDependencies": {
- "typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
+ "eslint": "^8",
+ "eslint-config-next": "14.2.3",
"postcss": "^8",
"tailwindcss": "^3.4.1",
- "eslint": "^8",
- "eslint-config-next": "14.2.3"
+ "typescript": "^5"
}
}
diff --git a/pages/[id].tsx b/pages/[id].tsx
new file mode 100644
index 0000000..01c0dbf
--- /dev/null
+++ b/pages/[id].tsx
@@ -0,0 +1,77 @@
+// import { useRouter } from "next/router";
+import Link from "next/link";
+import Image from "next/image";
+
+interface Recipe {
+ id: number;
+ name: string;
+ image: string;
+}
+export default function DynamicRount({ recipe }: { recipe: Recipe }) {
+ // const router = useRouter();
+ // const { id } = router.query;
+ // console.log(router);
+ return (
+
+
+
+ This page is about dynamic route
+
+ Back
+
+
Post: {recipe.id}
+
+
+ );
+}
+
+export async function getStaticProps({
+ params,
+}: {
+ params: { id: string | number };
+}) {
+ const id = params.id;
+ const res = await fetch(`https://dummyjson.com/recipes/${id}`);
+ const recipe = await res.json();
+ return { props: { recipe } };
+}
+
+export async function getStaticPaths() {
+ const url = `https://dummyjson.com/recipes`;
+ const res = await fetch(url);
+ const dummy = await res.json();
+ const recipes = dummy.recipes;
+ // console.log(recipes);
+ // console.log(Array.isArray(recipes)); // Should print true if recipes is an array
+
+ const paths = recipes.map((recipe: Recipe) => {
+ return {
+ params: { id: recipe.id.toString() },
+ };
+ });
+ // const paths = recipes.map((recipe: Recipe) => {
+ // return {
+ // params: { id: String(recipe.id) },
+ // };
+ // });
+
+ return {
+ paths,
+ // fallback: true,
+ fallback: false,
+ };
+}
diff --git a/pages/_app.tsx b/pages/_app.tsx
index a7a790f..dba9c47 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -1,6 +1,16 @@
import "@/styles/globals.css";
import type { AppProps } from "next/app";
+import Layout from "./layout";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+
+const queryClient = new QueryClient();
export default function App({ Component, pageProps }: AppProps) {
- return ;
+ return (
+
+
+
+
+
+ );
}
diff --git a/pages/components/event/ListenClick.tsx b/pages/components/event/ListenClick.tsx
index b97a7e6..eb215c3 100644
--- a/pages/components/event/ListenClick.tsx
+++ b/pages/components/event/ListenClick.tsx
@@ -1,6 +1,6 @@
export default function ListenClick() {
function handleClick() {
- console.log("increment like count");
+ // console.log("increment like count");
}
return (