mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
feat: add TuonoProps type
This commit is contained in:
@@ -8,7 +8,7 @@ export default function RootRoute({ children }: RootRouteProps): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<nav>
|
||||
Navbar: <Link>About</Link>
|
||||
Navbar: <Link href="/">Home</Link> | <Link href="/about">About</Link>
|
||||
</nav>
|
||||
<main>{children}</main>
|
||||
</>
|
||||
|
||||
@@ -3,14 +3,12 @@ use tuono_lib::{Request, Response};
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct MyResponse<'a> {
|
||||
title: &'a str,
|
||||
subtitle: &'a str,
|
||||
description: &'a str,
|
||||
}
|
||||
|
||||
#[tuono_lib::handler]
|
||||
fn get_server_side_props(req: &Request) -> Response {
|
||||
Response::Props(Box::new(MyResponse {
|
||||
title: "title",
|
||||
subtitle: "subtitle",
|
||||
description: "This descriptions comes from the rust server",
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
export default function IndexPage(): JSX.Element {
|
||||
return <h1>Index Page</h1>
|
||||
import type { TuonoProps } from 'tuono'
|
||||
|
||||
type IndexProps = {
|
||||
description: string
|
||||
}
|
||||
export default function IndexPage({
|
||||
data,
|
||||
isLoading,
|
||||
}: TuonoProps<IndexProps>): JSX.Element {
|
||||
if (isLoading) {
|
||||
return <h1>Loading...</h1>
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1>Index Page</h1>
|
||||
<p>{data?.description}</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,4 +6,6 @@ import {
|
||||
RouterProvider,
|
||||
} from './router'
|
||||
|
||||
export type { TuonoProps } from './types'
|
||||
|
||||
export { createRoute, createRootRoute, createRouter, Link, RouterProvider }
|
||||
|
||||
@@ -45,7 +45,8 @@ export function useServerSideProps(
|
||||
;(async (): Promise<void> => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const res = await fetch(`/__tuono/data/${route.path}`)
|
||||
const path = route.path === '/' ? '' : route.path
|
||||
const res = await fetch(`/__tuono/data/${path}`)
|
||||
setData(await res.json())
|
||||
} catch (error) {
|
||||
// Handle here error
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface TuonoProps<T> {
|
||||
data?: T
|
||||
isLoading: boolean
|
||||
}
|
||||
Reference in New Issue
Block a user