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,24 @@
|
||||
import type { Data } from "./+data";
|
||||
import { useData } from "~/renderer/hooks";
|
||||
import Link from "~/renderer/link";
|
||||
|
||||
const HomePage = () => {
|
||||
const { posts } = useData<Data>();
|
||||
if (!posts?.length) {
|
||||
return <p>No posts.</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Posts</h1>
|
||||
|
||||
{posts.map((post: any) => (
|
||||
<Link key={post.id} href={`/${post.id}`}>
|
||||
{post.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default HomePage;
|
||||
@@ -0,0 +1,9 @@
|
||||
export const data = async () => {
|
||||
const posts = await fetch(
|
||||
"https://jsonplaceholder.typicode.com/posts?_limit=20"
|
||||
).then((response) => response.json());
|
||||
|
||||
return { posts };
|
||||
};
|
||||
|
||||
export type Data = Awaited<ReturnType<typeof data>>;
|
||||
Reference in New Issue
Block a user