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
Multi-series data
API Reference
Return value
How it works
- Initialization: Starts with initialData trimmed to windowSize
- New point creation: Every intervalMs, creates a new data point
- Interpolation: Smoothly animates from current to target values
- Sliding window: Maintains only the last windowSize points
- 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
Related hooks
- useStreamingViewport - Similar but with dynamic viewport adjustment