From dc6341a4b16abe73da126138234a89a3ca6a6dde Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Tue, 22 Oct 2024 10:12:50 +0200 Subject: [PATCH] add components with server side resource --- src/components/SSRLabel.tsx | 21 +++++++++++++++++++++ src/routes/about.tsx | 20 +++----------------- src/routes/index.tsx | 20 +++----------------- 3 files changed, 27 insertions(+), 34 deletions(-) create mode 100644 src/components/SSRLabel.tsx diff --git a/src/components/SSRLabel.tsx b/src/components/SSRLabel.tsx new file mode 100644 index 0000000..3d7ba66 --- /dev/null +++ b/src/components/SSRLabel.tsx @@ -0,0 +1,21 @@ +import { createResource, createSignal, Match, Switch } from "solid-js"; + +function fetchServerResource(): Promise { + "use server"; + return new Promise((resolve) => { + setTimeout(() => { + resolve("Hello from the server!"); + }, 1000); + }); +} + +export default function SSRLabel() { + const [data] = createResource(fetchServerResource); + return ( + + Loading... + Error: {data.error} + {data()} + + ); +} diff --git a/src/routes/about.tsx b/src/routes/about.tsx index 1321ac3..4e365f7 100644 --- a/src/routes/about.tsx +++ b/src/routes/about.tsx @@ -1,24 +1,10 @@ -import { A } from "@solidjs/router"; -import Counter from "~/components/Counter"; +import SSRLabel from "~/components/SSRLabel"; export default function About() { return (
-

About Page

- -

- Visit{" "} - - solidjs.com - {" "} - to learn how to build Solid apps. -

-

- - Home - - {" - "} - About Page +

+

); diff --git a/src/routes/index.tsx b/src/routes/index.tsx index a5d2efe..6deeb09 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,24 +1,10 @@ -import { A } from "@solidjs/router"; -import Counter from "~/components/Counter"; +import SSRLabel from "~/components/SSRLabel"; export default function Home() { return (
-

Hello world!

- -

- Visit{" "} - - solidjs.com - {" "} - to learn how to build Solid apps. -

-

- Home - {" - "} - - About Page - {" "} +

+

);