-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use nanojsx #42
Comments
Based on the example and the
// deno run --watch --no-clear-screen --allow-net=0.0.0.0:8000 web.tsx
/// <reference no-default-lib="true"/>
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/** @jsx h */
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { h, ssr } from "./webssr.ts";
import { sheet, stringify, tw } from "./webtw.ts";
const Hello = (props: { name: string }) => (
<div class={tw`bg-white flex h-screen`}>
<h1 class={tw`text-indigo-500 p-5 text-xl font-semibold`}>
Hello {props.name}!
</h1>
</div>
);
if (import.meta.main) {
console.log("Listening on http://localhost:8000");
await serve((req) => {
const url = new URL(req.url);
const name = url.searchParams.get("name") ?? "world";
return new Response(
ssr(
() => h(<Hello name={name} />),
() => stringify(sheet.target),
),
{ headers: { "content-type": "text/html" } },
);
});
}
import {
h,
Helmet,
renderSSR,
} from "https://deno.land/x/[email protected]/mod.ts";
export function ssr(render: CallableFunction, renderStyles: CallableFunction) {
const app = renderSSR(render());
const styles = renderStyles();
const { body, head, footer } = Helmet.SSR(app);
return `
<html>
<head>
${head}
<style>${styles}</style>
</head>
<body>
${body}
${footer}
</body>
</html>
`;
}
export { h };
import {
stringify,
twind,
virtual,
} from "https://cdn.skypack.dev/[email protected]";
import presetTailwind from "https://cdn.skypack.dev/@twind/[email protected]";
export const sheet = virtual();
export const tw = twind({
presets: [
presetTailwind({ disablePreflight: false }),
],
}, sheet);
export { stringify }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems to be helpful to build single-page apps quickly. I like how simple this example is.
The text was updated successfully, but these errors were encountered: