FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
dcm31
dcm31diceRollerUI
A web-based dice roller using React on Val Town
Public
Like
diceRollerUI
Home
Code
2
GUIDE.md
H
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
GUIDE.md
Code
/
GUIDE.md
Search
5/1/2025
Viewing readonly version of main branch: v9
View latest version
GUIDE.md

🧠 Val Town UI Project Guide for Future Me

This is a checklist + guide to avoid the mistakes we made while building simple UIs (like Dice Roller).

βœ… Entry File

  • Must be named: main.tsx
  • Must be of type: http
  • Must export a default async function server() that returns HTML
  • Must include a client() function that calls createRoot(...).render(...)
  • Must include hydration logic:
    Create val
    if (typeof document !== "undefined") client();
  • client() must be re-exported:
    Create val
    export { client };

βœ… React Import Rules

  • At the top, include:
    Create val
    /** @jsxImportSource https://esm.sh/react@18.2.0 */
  • Import from URLs:
    Create val
    import { createRoot } from "https://esm.sh/react-dom@18.2.0/client"; import { useState } from "https://esm.sh/react@18.2.0";

βœ… HTML Boilerplate

The server() function should return:

Create val
return new Response(`<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My App</title> <script type="module"> import { client } from "${import.meta.url}"; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', client); } else { client(); } </script> </head> <body> <div id="root"></div> </body> </html>`, { headers: { "content-type": "text/html; charset=utf-8" } });

βœ… Style Guide

  • Use Tailwind classes for layout, spacing, buttons, etc.
  • Optionally import from CDN or inject inline CSS.

πŸ›  Recap Workflow

  1. Create a Val with http type file main.tsx
  2. Set up JSX import and server() / client() boilerplate
  3. Build your UI in a function App() and render it inside client()
  4. Return correct HTML in server()
  5. Add a moi.md with title, url, image, and tags

You’re ready to make any UI with just "make a X". πŸš€

Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesCLIAI agentsCode intelligenceSlack integrationsGTMPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.