FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
lightweight
lightweightglimpse2-runbook-view-glimpse-save-login-react
Remix of lightweight/glimpse2-runbook-view-glimpse-save-login
Public
Like
glimpse2-runbook-view-glimpse-save-login-react
Home
Code
8
_townie
13
backend
7
frontend
9
shared
3
.vtignore
README.md
deno.json
H
main.tsx
Branches
2
Pull requests
Remixes
History
Environment variables
6
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
/
frontend
/
hooks
/
README.md
Code
/
frontend
/
hooks
/
README.md
Search
…
README.md

Frontend Hooks

This directory contains custom React hooks that encapsulate stateful logic and side effects.

Files

useAuth.ts

Handles authentication and authorization logic.

Returns: UseAuthReturn

  • userEmail - Current user's email from window data
  • isAuthorized(pageProperties) - Function to check if user can access a page

Usage:

const { userEmail, isAuthorized } = useAuth(); const canView = isAuthorized(pageProperties);

useGlimpseData.ts

Manages glimpse data fetching and state.

Parameters:

  • glimpseId - ID of the glimpse to fetch
  • initialData - Optional initial data to avoid refetching

Returns: UseGlimpseDataReturn

  • data - Current glimpse data
  • loading - Loading state
  • error - Error state
  • refetch - Function to manually refetch data

Usage:

const { data, loading, error, refetch } = useGlimpseData(glimpseId, initialData);

useAgentData.ts

Manages agent data fetching with automatic polling.

Parameters:

  • glimpseId - ID of the glimpse
  • isAuthorized - Whether user is authorized (controls polling)

Returns: UseAgentDataReturn

  • agentData - Current agent data
  • hasAgents - Boolean indicating if agents exist

Usage:

const { agentData, hasAgents } = useAgentData(glimpseId, isAuthorized);

useViewingTracking.ts

Handles viewing status tracking with automatic updates and reliable session ending.

Parameters:

  • glimpseId - ID of the glimpse being viewed
  • isAuthorized - Whether user is authorized (controls tracking)

Side Effects:

  • Sends initial viewing status update on mount
  • Sends periodic viewing status updates every 10 seconds
  • Tracks page visibility changes (tab focus/blur)
  • Handles page unload events for reliable session ending
  • Cleans up all listeners and intervals on unmount

Session Tracking:

  • Uses sendBeacon API for reliable session ending during page unload
  • Falls back to synchronous fetch if sendBeacon fails
  • Handles both normal component unmount and browser tab closure

Usage:

useViewingTracking(glimpseId, isAuthorized);

Benefits

  • Reusable logic: Hooks can be used across multiple components
  • Separation of concerns: Stateful logic separate from rendering
  • Easier testing: Hooks can be tested independently
  • Better performance: Optimized state management and cleanup
  • Consistent patterns: Standardized approach to common operations
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.