ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.0 KiB

  1. import React, { useEffect, useState } from 'react'
  2. import { Link } from 'react-router-dom'
  3. import axios from 'axios'
  4. import { API_BASE_URL, SITE_TITLE } from '../config'
  5. const HomePage = () => {
  6. const [posts, setPosts] = useState([])
  7. useEffect(() => {
  8. const fetchPosts = async () => {
  9. try {
  10. const response = await axios.get(`${ API_BASE_URL }/posts`)
  11. setPosts(response.data)
  12. } catch (error) {
  13. console.error('Failed to fetch posts:', error)
  14. }
  15. }
  16. fetchPosts()
  17. document.title = `${ SITE_TITLE } 〜 ぼざクリも、ぼざろ外も、外伝もあるんだよ。`
  18. }, [])
  19. return (
  20. <div className="flex flex-wrap gap-4 p-4">
  21. {posts.map (post => (
  22. <Link
  23. to={`/posts/${post.id}`}
  24. key={post.id}
  25. className="w-40 h-40 overflow-hidden rounded-lg shadow-md hover:shadow-lg"
  26. >
  27. <img
  28. src={post.thumbnail}
  29. className="object-cover w-full h-full"
  30. />
  31. </Link>
  32. ))}
  33. </div>
  34. )
  35. }
  36. export default HomePage