Interactive Wallpaper
In this tutorial, you'll build a wallpaper that responds to your mouse cursor using the useMousePosition hook.
Prerequisites
Complete the Getting Started tutorial first.
Add Mouse Tracking
Replace the content of src/main.tsx:
src/main.tsx
Start the dev server and move your mouse — the glowing circle follows your cursor across the screen.
Understanding the Coordinate System
useMousePosition() returns coordinates normalized to the wallpaper window: both x and y range from -1 to 1. The Y axis is mathematical (+1 = top, -1 = bottom), so it's inverted relative to CSS — convert with ((x + 1) / 2) * window.innerWidth and (1 - (y + 1) / 2) * window.innerHeight before using as pixel offsets.
Adding Animation Libraries
For smoother animations, you can use libraries like @react-spring/web:
src/main.tsx
Next Steps
Task-focused guides:
- Track Mouse Position — Practical patterns for
useMousePosition. - React to Audio — Drive your wallpaper from audio instead of mouse.
- Custom Properties — Let users tweak colors and sizes.
Another tutorial:
- Shell Wallpaper — Display system info on your wallpaper.
API reference: