mirror of
https://github.com/khairul169/code-share.git
synced 2026-10-24 11:53:58 +07:00
feat: rebuild app using vike
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { useData } from "~/renderer/hooks";
|
||||
import { Data } from "./+data";
|
||||
import Link from "~/renderer/link";
|
||||
|
||||
const ViewPostPage = () => {
|
||||
const { post } = useData<Data>();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Link href="/">Go Back</Link>
|
||||
<h1>{post.title}</h1>
|
||||
<p>{post.body}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ViewPostPage;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PageContext } from "vike/types";
|
||||
|
||||
export const data = async (ctx: PageContext) => {
|
||||
const id = ctx.routeParams?.id;
|
||||
const post = await fetch(
|
||||
"https://jsonplaceholder.typicode.com/posts/" + id
|
||||
).then((response) => response.json());
|
||||
|
||||
return { post, title: post?.title };
|
||||
};
|
||||
|
||||
export type Data = Awaited<ReturnType<typeof data>>;
|
||||
Reference in New Issue
Block a user