199- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
200- For persistence, use Val Town SQLite or Blob storage with `import.meta.url` for keys/table names
201- **React Configuration:** When using React libraries, pin versions with `?deps=react@18.2.0,react-dom@18.2.0` and include the `@jsxImportSource` pragma
202- When facing client-side render issues, check if all React dependencies are pinned to the same version
203- **Styling:** Default to using TailwindCSS via `<script src="https://cdn.twind.style" crossorigin></script>` unless otherwise specified
204
262
263### Frontend Best Practices
264- Structure as a standard client-side React app
265- Use SVG for favicons (Val Town only supports text files)
266- Separate components into individual files
267- Access bootstrapped data from `window.__INITIAL_DATA__`
268- Use React 18.2.0 consistently in all imports and the `@jsxImportSource` pragma
269- Follow the React component pattern from the example project
270- Handle API calls properly with proper error catching
271
289 - Always run table creation before querying
290
2913. **React Configuration:**
292 - All React dependencies must be pinned to 18.2.0
293 - Always include `@jsxImportSource https://esm.sh/react@18.2.0` at the top of React files
294 - Rendering issues often come from mismatched React versions
295
2964. **File Handling:**
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, {
3 useState,
4 useEffect,
5 useCallback,
6 useMemo,
7} from "https://esm.sh/react@18.2.0";
8import { type Memory } from "../../shared/types.ts";
9import { ASSETS, SCENE_POSITIONS, SOURCE_TYPES } from "./assets.ts";
165 }, [fetchMemories]);
166
167 const handleAddMemory = async (e: React.FormEvent) => {
168 e.preventDefault();
169 if (!newMemoryText.trim()) return;
220 };
221
222 const handleUpdateMemory = async (e: React.FormEvent) => {
223 e.preventDefault();
224 if (!editingMemory || !editingMemory.text.trim()) return;
17 // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18 // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19 // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20 // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21 // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22 // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23 // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24 // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
3import React, { useState } from "https://esm.sh/react@18.2.0";
4
5const NO_PHRASES = [
1/** @jsxImportSource /react */
2import { renderToString } from "https://esm.sh/react-dom/server";
3
4import React, { useCallback, useEffect, useRef, useState } from "https://esm.sh/react";
5
6/* ---------- Types ---------- */
24 scoreWeights?: Partial<Scores>;
25 onFocusChange?: (node: NavNode<T>) => void;
26 renderNode: (node: NavNode<T>, focused: boolean) => React.ReactNode;
27 className?: string;
28 gridCols?: number;
150 const touch = useRef<{ x: number; y: number } | null>(null);
151
152 const onTouchStart = useCallback((e: React.TouchEvent) => {
153 const t = e.touches[0];
154 touch.current = { x: t.clientX, y: t.clientY };
155 }, []);
156
157 const onTouchEnd = useCallback((e: React.TouchEvent) => {
158 if (!touch.current) return;
159 const t = e.changedTouches[0];
226}
227
228// Example Usage (React)
229interface Race {
230 name: string;
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function TownieIcon({
1import { useEffect } from "https://esm.sh/react@18.2.0?dev";
2
3export function useUsageStats (messages: any[], usages: any[]) {
1import { useEffect, useRef } from 'https://esm.sh/react@18.2.0?dev';
2
3
1import { useState, useEffect } from "https://esm.sh/react@18.2.0?dev";
2import { useAuth } from "./useAuth.tsx";
3
1import { useState, useEffect } from "https://esm.sh/react@18.2.0?dev";
2import { useAuth } from "./useAuth.tsx";
3