#49 ページの移動

このコミットが含まれているのは:
2025-06-28 02:43:57 +09:00
コミット 72a567e519
9個のファイルの変更9行の追加61行の削除
-50
ファイルの表示
@@ -1,50 +0,0 @@
import React, { useEffect, useState } from 'react'
import axios from 'axios'
import { useParams } from 'react-router-dom'
import { API_BASE_URL } from '../config'
import MainArea from '@/components/layout/MainArea'
export default () => {
const { id } = useParams()
const [posts, setPosts] = useState([])
const [tagName, setTagName] = useState('')
useEffect (() => {
const fetchTag = async () => {
try {
const response = await axios.get (`${API_BASE_URL}/tags/${id}`)
setTagName (response.data.name)
} catch (error) {
console.error ('Error fetching tag:', error)
}
}
const fetchPosts = async () => {
try {
const response = await axios.get (`${API_BASE_URL}/tags/${id}/posts`)
setPosts (response.data)
} catch (error) {
console.error ('Error fetching posts:', error)
}
}
fetchTag ()
fetchPosts ()
}, [id])
return (
<MainArea>
<div className="container mx-auto p-4">
<h1 className="text-2xl font-bold mb-4">: {tagName}</h1>
<div className="grid grid-cols-4 gap-4">
{posts.map ((post, index) => (
<div key={index} className="border rounded p-2">
<img src={post.image_url} alt={post.title} className="w-full h-48 object-cover mb-2" />
<h2 className="text-lg font-semibold">{post.title}</h2>
</div>
))}
</div>
</div>
</MainArea>)
}