Skip to main content
100%

React & D3 Drag with useReducer

✓ Published1🌍 Public
CCurran Kelleher
Last edited May 16, 2023
Created on May 16, 2023
Forked from React & D3 Drag

This example shows three draggable circles connected by thick black lines in an SVG canvas. The circles and lines are rendered and updated using D3.js selectors and join operations, while React manages the application state. Dragging any circle dispatches a `drag` action to a `useReducer` hook, updating the circle’s x and y coordinates in the central state object. The D3 `drag` handler triggers the callback, and the Vue-like wrapper re-renders the visualization via the `viz.js` module. Animated interactivity is demonstrated through mouse hover effects and real-time position updates.

AI-generated description

A basic demonstration of d3-drag used with React to drag circles connected by lines.

This variant uses useReducer to avoid creating a new closure on each render.

Inspired by Observable: Drag (SVG).

MIT Licensed

Similar vizzes