Skip to main content
100%

Mouse Follower

✓ Published1🌍 Public
CChristopher Cleland
Last edited Sep 12, 2021
Created on Sep 12, 2021

This example shows a single circle that follows the mouse cursor across an SVG canvas. Built with React and D3 v5, it uses React’s `useState` hook to track the cursor’s clientX and clientY coordinates on every `mousemove` event, then re-renders the circle’s `cx` and `cy` attributes to match. The `useCallback` hook memoizes the event handler, and the initial mouse position is set to the canvas center. The rendering uses ReactDOM to mount the SVG, with no external data source.

AI-generated description

A program that follows your mouse

MIT Licensed

Similar vizzes