Search

Results include substring matches and semantically similar vals. Learn more
tfayyaz avatar
reacttldrawclient
@tfayyaz
@jsxImportSource https://esm.sh/react@18.2.0
Script
/** @jsxImportSource https://esm.sh/react@18.2.0 **/
// Make sure to only import from esm.sh (npm: specifier are not supported in the browser)
import ReactDOM from "https://esm.sh/react-dom@18.2.0";
import React from "https://esm.sh/react@18.0.0";
import { useState } from "https://esm.sh/react@18.0.0";
import { Tldraw } from "https://esm.sh/tldraw@2.1.0";
</div>
// The app will be rendered inside the root div
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
isidentical avatar
fluxImageGenerator
@isidentical
Sign in to fal.ai, generate an API key, and set it as FAL_KEY for your account.
HTTP
// React is used for the UI and the fal.ai serverless client for image generation.
/** @jsxImportSource https://esm.sh/react */
import * as fal from "https://esm.sh/@fal-ai/serverless-client";
import React, { useEffect, useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function client() {
client();
async function checkRateLimit(clientIP: string): Promise<boolean> {
const key = `xratelimit_${clientIP}`;
let clientData = await blob.getJSON<RateLimitData>(key);
stevekrouse avatar
TodoApp
@stevekrouse
SSR React Mini & SQLite Todo App This Todo App is server rendered and client-hydrated React. This architecture is a lightweight alternative to NextJS, RemixJS, or other React metaframeworks with no compile or build step. The data is saved server-side in Val Town SQLite . SSR React Mini Framework This "framework" is currently 44 lines of code, so it's obviously not a true replacement for NextJS or Remix. The trick is client-side importing the React component that you're server rendering . Val Town is uniquely suited for this trick because it both runs your code server-side and exposes vals as modules importable by the browser. The tricky part is making sure that server-only code doesn't run on the client and vice-versa. For example, because this val colocates the server-side loader and action with the React component we have to be careful to do all server-only imports (ie sqlite) dynamically inside the loader and action , so they only run server-side.
HTTP (deprecated)
# SSR React Mini & SQLite Todo App
This Todo App is server rendered *and* client-hydrated React. This architecture is a lightweight alternative to NextJS, Remix
## SSR React Mini Framework
This ["framework"](https://www.val.town/v/stevekrouse/ssr_react_mini) is currently 44 lines of code, so it's obviously not a
The trick is [client-side importing](https://www.val.town/v/stevekrouse/ssr_react_mini?v=53#L30) the React component that you
The tricky part is making sure that server-only code doesn't run on the client and vice-versa. For example, because this val
/** @jsxImportSource https://esm.sh/react */
import { useEffect, useState } from "https://esm.sh/react@18.2.0";
import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
useEffect(() => addLog(`Client rendered`), []);
tmcw avatar
reacttldrawclient
@tmcw
@jsxImportSource https://esm.sh/react@18.2.0
Script
/** @jsxImportSource https://esm.sh/react@18.2.0 **/
// Make sure to only import from esm.sh (npm: specifier are not supported in the browser)
import ReactDOM from "https://esm.sh/react-dom@18.2.0";
import React from "https://esm.sh/react@18.2.0";
import { useState } from "https://esm.sh/react@18.2.0";
import { Tldraw } from "https://esm.sh/tldraw@2.1.0";
</div>
// The app will be rendered inside the root div
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
ejfox avatar
eldestBronzePtarmigan
@ejfox
* This dating app allows users to upload photos of their bedside table and phone case. * It uses Val Town's SQLite for data persistence and blob storage for image uploads. * The app includes a simple matching algorithm based on common items in bedside tables.
HTTP
* This dating app allows users to upload photos of their bedside table and phone case.
* The app includes a simple matching algorithm based on common items in bedside tables.
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
const [bedsideImage, setBedsideImage] = useState(null);
setBedsideImage(userData.bedsideImage);
if (type === 'bedside') {
setBedsideImage(result.imageUrl);
<h1>Bedside & Case Dating App</h1>
hugenshen avatar
httpHelloWorld
@hugenshen
// This approach creates a PC application with a left-side menu structure as requested.
HTTP
// This approach creates a PC application with a left-side menu structure as requested.
// We'll use React for the UI components and React Router for navigation.
// The server will serve the HTML, and the client-side React application will handle the menu and routing.
/** @jsxImportSource https://esm.sh/react */
import ReactDOM from "https://esm.sh/react-dom@18.2.0";
import { BrowserRouter, Link, Route, Routes } from "https://esm.sh/react-router-dom@6.11.2";
import React from "https://esm.sh/react@18.2.0";
const [isOpen, setIsOpen] = React.useState(false);
const [isHovered, setIsHovered] = React.useState(false);
function client() {
Olive avatar
linkInBioTemplate
@Olive
* This web app creates a Side School Seminar location voting system. * Users can vote for their preferred seminar location from four options. * The app uses React for the frontend and SQLite for storing votes on the backend. * The design is inspired by Side.school and includes an image in the first frame. * It features a celebration animation when voting, a distinct style for the selected option, * and allows users to cancel their vote by clicking on the selected option again.
HTTP (deprecated)
* This web app creates a Side School Seminar location voting system.
* The app uses React for the frontend and SQLite for storing votes on the backend.
* The design is inspired by Side.school and includes an image in the first frame.
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
<h1>Side School Seminar</h1>
function client() {
client();
<title>Side School Seminar</title>
ejfox avatar
typingTestSpectrogram
@ejfox
// This app creates a 10-second typing test with audio recording and spectrogram visualization.
HTTP
// TailwindCSS is used for styling.
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect, useRef } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
</div>
function client() {
console.log("Client-side code running");
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
async function server(request: Request): Promise<Response> {
jxnblk avatar
resrv
@jxnblk
React SSR and client-side hydration for Val Town For streaming responses use ReactStream Usage /** @jsxImportSource https://esm.sh/react */ import resrv, { React } from "https://esm.town/v/jxnblk/resrv"; function App() { const [count, setCount] = React.useState(0); return ( <div> <h1>Resrv</h1> <p>React SSR with client-side hydration in Val Town</p> <pre>{count}</pre> <button onClick={() => setCount(count - 1)}>-</button> <button onClick={() => setCount(count + 1)}>+</button> </div> ); } export default resrv(App, import.meta.url); Live example React requires matching versions for SSR and hydration. Import React from https://esm.town/v/jxnblk/resrv to ensure your component uses the same version as this library (currently react@18.3.1). HTML Root Hydration To render a component that includes a <head> and <body> tag, pass root: true to the third options argument: function App ({ script }) { return ( <body> <h1>Hello</h1> {script} </body> ); } export default resrv(App, import.meta.url, { root: true }); Inspired by https://www.val.town/v/stevekrouse/react_http
Script
React SSR and client-side hydration for Val Town
For streaming responses use [ReactStream]
[ReactStream]: https://www.val.town/v/jxnblk/ReactStream
/** @jsxImportSource https://esm.sh/react */
import { renderToString } from "https://esm.sh/react-dom@18.3.1/server";
import * as React from "https://esm.sh/react@18.3.1";
// import resrv, { React } from "https://esm.town/v/jxnblk/resrv";
export { React };
import { hydrateRoot } from "https://esm.sh/react-dom@18.3.1/client";
import { jsx } from "https://esm.sh/react@18.3.1/jsx-runtime";
janpaul123 avatar
reacttldrawclient
@janpaul123
tldraw example with builder, for consistent React versions.
Script
tldraw example with builder, for consistent React versions.
/** @jsxImportSource https://esm.sh/react@18.3.1 **/
"react-dom": "18.3.1",
"react": "18.3.1",
export * as ReactDOM from "react-dom";
export * as React from "react";
ReactDOM,
React,
<tldraw.Tldraw persistenceKey="valtown_reacttldrawclient" cameraOptions={{ wheelBehavior: "zoom" }} />
// The app will be rendered inside the root div
const root = ReactDOM.createRoot(document.getElementById("root"));
all avatar
TufteCSS
@all
CSS Explorer [ ] Add Flexgrid [x] Pill box style navigation [ ] Tufte-inspired CSS [ ] React [ ] Lorum Ipsum Text Sample with all features [ ] Admonishments [ ] MARP explorer with navigation buttons [ ] Edit sliders to left [ ] Colors on Bottom [ ] "Scramble" Feature [ ] Full CSS download
HTTP
- [ ] Tufte-inspired CSS
- [ ] React
- [ ] Lorum Ipsum Text Sample with all features
* This val creates a Tufte-inspired CSS Navigator app with React for the client-side UI
* and a server-side handler for serving the HTML. The app allows users to explore different
* CSS styles, copy and download them, change themes, view sample text that displays
* the selected style, choose accent colors, and adjust extra options like font size and line height.
/** @jsxImportSource https://esm.sh/react */
import React, { useEffect, useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
const cssStyles = {
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") {
client();
export default async function server(request: Request): Promise<Response> {
movienerd avatar
clickerGame
@movienerd
* This clicker game allows users to earn virtual money by clicking. * It includes an upgrade system where users can purchase multiple auto-clickers, dime-smithers, quarter-makers, dollar-mills, twoonie-transformers, fiver-factories, ten-trackers, twenty-detectors, fifty-forgers, and hundred-hewers. * Each upgrade adds to the overall effect, increasing earnings per second. * Upgrades are hidden until they are unlocked for the first time. * The game state is stored client-side using localStorage for persistence. * React is used for the UI, and setInterval for the auto-upgrade functionality.
HTTP
* Upgrades are hidden until they are unlocked for the first time.
* The game state is stored client-side using localStorage for persistence.
* React is used for the UI, and setInterval for the auto-upgrade functionality.
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
setMoney(m => m + 0.01);
const buyUpgrade = (cost: number, setter: React.Dispatch<React.SetStateAction<number>>) => {
if (money >= cost) {
const formatMoney = (amount: number) => amount.toFixed(2);
nst renderUpgradeButton = (name: string, cost: number, count: number, setter: React.Dispatch<React.SetStateAction<number>>, u
if (!unlocked) return null;
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
async function server(request: Request): Promise<Response> {
mjweaver01 avatar
TodoApp
@mjweaver01
SSR React Mini & SQLite Todo App This Todo App is server rendered and client-hydrated React. This architecture is a lightweight alternative to NextJS, RemixJS, or other React metaframeworks with no compile or build step. The data is saved server-side in Val Town SQLite . SSR React Mini Framework This "framework" is currently 44 lines of code, so it's obviously not a true replacement for NextJS or Remix. The trick is client-side importing the React component that you're server rendering . Val Town is uniquely suited for this trick because it both runs your code server-side and exposes vals as modules importable by the browser. The tricky part is making sure that server-only code doesn't run on the client and vice-versa. For example, because this val colocates the server-side loader and action with the React component we have to be careful to do all server-only imports (ie sqlite) dynamically inside the loader and action , so they only run server-side.
HTTP (deprecated)
# SSR React Mini & SQLite Todo App
This Todo App is server rendered *and* client-hydrated React. This architecture is a lightweight alternative to NextJS, Remix
## SSR React Mini Framework
This ["framework"](https://www.val.town/v/stevekrouse/ssr_react_mini) is currently 44 lines of code, so it's obviously not a
The trick is [client-side importing](https://www.val.town/v/stevekrouse/ssr_react_mini?v=53#L30) the React component that you
The tricky part is making sure that server-only code doesn't run on the client and vice-versa. For example, because this val
/** @jsxImportSource https://esm.sh/react */
import { useEffect, useState } from "https://esm.sh/react@18.2.0";
import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
useEffect(() => addLog(`Client rendered`), []);
pomdtr avatar
example_ssr
@pomdtr
SSR + Hydration Demo Look at @pomdtr/island and @pomdtr/hydrate_islands to read the whole library source code (less than 50 rows!).
HTTP (deprecated)
/** @jsxImportSource https://esm.sh/react */
import { useEffect, useState } from "https://esm.sh/react";
// will run on both client and server
export function Demo(props: { items: string[] }) {
useEffect(() => {
items.push("This item is rendered only on the client, after the hydration");
setItems([...items]);
if (url.pathname == "/api/item") {
return Response.json("This item is fetched from the server by the client");
// server-side import should only be used here
const { Island } = await import("https://esm.town/v/pomdtr/island");
const { renderToString } = await import("https://esm.sh/react-dom/server");
return new Response(
items={[
"This item is rendered both on the server and the client",
</Island>
movienerd avatar
clicker
@movienerd
This is a simple idle clicker game written almost entirely by AI and directed by prompts.
HTTP
* This code creates a Money Clicker Game using React for the UI.
* It uses localStorage for client-side persistence and setInterval for auto-upgrades.
* The game features a pixelated, retro-inspired design reminiscent of early computer games.
* The upgrade-info-container is now hidden when not on the Clickers tab.
/** @jsxImportSource https://esm.sh/react */
import React, { useEffect, useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
setMoney(m => m + 0.01);
const buyUpgrade = (cost: number, setter: React.Dispatch<React.SetStateAction<number>>) => {
if (money >= cost) {
count: number,
setter: React.Dispatch<React.SetStateAction<number>>,
unlocked: boolean,
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
async function server(request: Request): Promise<Response> {