|
1 | | -import React from "react"; |
| 1 | +"use client"; |
| 2 | + |
| 3 | +import React, { useEffect, useState } from "react"; |
| 4 | +import { useParams } from "next/navigation"; |
| 5 | +import { blogData } from "@/static/blog"; |
2 | 6 | import { BlogItem } from "@/types/blog"; |
3 | 7 | import DetailHero from "./DetailHero"; |
4 | 8 | import DetailContent from "./DetailContent"; |
5 | 9 |
|
6 | | -const BlogDeatails = ({ image, title, content, author }: BlogItem) => { |
| 10 | +const BlogDeatails = () => { |
| 11 | + const params = useParams(); // get id from URL |
| 12 | + const [post, setPost] = useState<BlogItem | null>(null); |
| 13 | + |
| 14 | + useEffect(() => { |
| 15 | + if (params?.id) { |
| 16 | + const found = blogData.find((b) => b.id.toString() === params.id); |
| 17 | + setPost(found || null); |
| 18 | + } |
| 19 | + }, [params?.id]); |
| 20 | + |
| 21 | + if (!post) return <div>Loading or blog not found...</div>; |
| 22 | + |
7 | 23 | return ( |
8 | 24 | <div className="flex flex-col"> |
9 | 25 | <DetailHero |
10 | | - imageSrc={image} |
11 | | - title={title} |
12 | | - authorName={author.name} |
13 | | - authorAvatar={author.avatar} |
14 | | - date={author.date} |
15 | | - readTime={author.readTime} |
16 | | - className="" |
| 26 | + imageSrc={post.image} |
| 27 | + title={post.title} |
| 28 | + authorName={post.author.name} |
| 29 | + authorAvatar={post.author.avatar} |
| 30 | + date={post.author.date} |
| 31 | + readTime={post.author.readTime} |
17 | 32 | /> |
18 | | - |
19 | | - <DetailContent content={content} /> |
| 33 | + <DetailContent content={post.content} /> |
20 | 34 | </div> |
21 | 35 | ); |
22 | 36 | }; |
|
0 commit comments