• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
jmccollum

jmccollum

br-iframe

Public
Like
br-iframe
Home
Code
3
README.md
index.html
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
/
Code
/
Search
main.tsx
https://jmccollum--b4e7f52e6da311f0bff30224a6c84d84.web.val.run
README.md

React Data Table Component

A React table component that handles message-based data updates using Zod schema validation. This component is designed to receive data through window.postMessage and display it in a clean, formatted table.

Features

  • Message-based data handling: Receives data through window.postMessage API
  • Zod schema validation: Validates incoming messages for type safety
  • Flexible data types: Handles strings, numbers, booleans, objects, and null values
  • Settings support: Accepts theme and readOnly settings
  • Auto-formatting: Automatically formats different data types for display
  • Responsive design: Clean, modern table styling with hover effects

Message Schema

The component accepts two types of messages:

Data Messages

{ type: 'data', data: { span_id?: string, input?: unknown, output?: unknown, expected?: unknown, metadata?: unknown, // ... any additional properties } }

Settings Messages

{ type: 'settings', settings: { theme?: 'light' | 'dark', readOnly?: boolean, // ... any additional settings } }

Usage

Sending Data

// Send data to the table window.postMessage({ type: 'data', data: { span_id: 'initial-sample', input: 'An orphaned boy discovers he\'s a wizard on his 11th birthday when Hagrid escorts him to magic-teaching Hogwarts School.', output: 'Harry Potter and the Philosopher\'s Stone', expected: 'Harry Potter and the Sorcerer\'s Stone', metadata: null } }, '*');

Sending Settings

// Update component settings window.postMessage({ type: 'settings', settings: { theme: 'dark', readOnly: true } }, '*');

Data Formatting

The component automatically formats different data types:

  • Strings: Displayed as-is
  • Numbers/Booleans: Converted to strings
  • Objects: Pretty-printed as JSON
  • null/undefined: Displayed as "null"
  • Complex objects: Fallback to "[Object]" if JSON.stringify fails

Example Data

The component includes a demo that automatically loads sample data:

Property: span_id
Value: initial-sample

Property: input  
Value: An orphaned boy discovers he's a wizard on his 11th birthday when Hagrid escorts him to magic-teaching Hogwarts School.

Property: output
Value: Harry Potter and the Philosopher's Stone

Property: expected
Value: Harry Potter and the Sorcerer's Stone

Property: metadata
Value: null

Testing

Open the browser console and run:

window.postMessage({ type: 'data', data: { span_id: 'test', input: 'test input', output: 'test output' } }, '*');

Technical Details

  • Built with React 18.2.0
  • Uses Zod for schema validation
  • Styled with custom CSS (no external UI library dependencies)
  • Handles message validation errors gracefully
  • Supports extensible schemas with catchall(z.unknown())
HTTP
  • main.tsx
    jmccollum--b4…84.web.val.run
Code
README.mdindex.html
H
main.tsx
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.