Skip to content
TrademarkTrademark
Docs
Hooks

useStreamingData

Updated: February 22, 2026
View on GitHub

The useStreamingData hook creates smooth, animated data streams for real-time visualizations. It interpolates between data points and maintains a sliding window of values, perfect for live charts and dashboards.

Used in components: Not used internally by Once UI components

This is a utility hook for building custom real-time data visualizations. Use it when you need to create live charts, dashboards, or streaming data displays with smooth animations.

Features

  • Smooth interpolation between data points
  • Configurable sliding window size
  • Customizable update intervals
  • Pause/resume streaming
  • Reset to initial state
  • RequestAnimationFrame-based updates

Basic usage

Create a streaming line chart:

Multi-series data

Stream multiple data series:

API Reference

Type
Default
initialData
T[]—
windowSize
number—
intervalMs
number—
stepMs
number16
xKey
keyof T—
numericKeys
Array<keyof T>—
getNextTarget
({ lastPoint, nextX }) => Partial<T>—

Return value

How it works

  1. Initialization: Starts with initialData trimmed to windowSize
  2. New point creation: Every intervalMs, creates a new data point
  3. Interpolation: Smoothly animates from current to target values
  4. Sliding window: Maintains only the last windowSize points
  5. Animation: Updates every stepMs using requestAnimationFrame

Performance tips

  • Use stepMs: 16 for 60fps (smooth)
  • Use stepMs: 33 for 30fps (more efficient)
  • Keep windowSize reasonable (20-50 points)
  • Avoid expensive calculations in getNextTarget

Real-world example

System monitoring dashboard:

  • useStreamingViewport - Similar but with dynamic viewport adjustment
Edit this page on GitHub