foundation for posts

This commit is contained in:
2026-09-06 22:05:10 -04:00
parent 41e5316443
commit 04e66527ca
6 changed files with 116 additions and 14 deletions
+40
View File
@@ -0,0 +1,40 @@
import Layout from "../components/layout";
import { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
import type { Post } from "../utils/types";
export default function Post() {
const [post, setPost] = useState<Post | null>(null);
const params = useParams();
useEffect(() => {
if (params.slug) {
fetch("/api/posts/" + params.slug, {
method: "GET",
credentials: "include",
}).then(async (res) => {
if (res.ok) {
const data = await res.json();
setPost(data);
} else {
console.error("Failed to load post! " + res.status);
}
});
}
}, []);
useEffect(() => {
console.log(post);
}, [post]);
if (post) {
return (
<Layout>
<div className="my-2">
<h1 className="text-2xl font-bold">{post.title}</h1>
<p className="text-sm opacity-50">{post.description}</p>
</div>
</Layout>
);
}
}