Skip to main content
100%

Building Interactivity with React

✓ Published1🌍 Public
Jjjacobatandover
Last edited Jul 10, 2021
Created on Jul 10, 2021

An interactive SVG circle follows the mouse as it moves across the screen, demonstrating how React manages state and event handling for dynamic visual updates. Built with React 17 and D3 v7, the component uses `useState` and `useCallback` to track the cursor position and update the circle's `cx` and `cy` attributes on every `mousemove`. The rendered output is a single yellow circle on a blank canvas, showcasing the integration of React's declarative JSX syntax with SVG elements inside a simple, resizable viewport.

AI-generated description

A bare minimum HTML page demonstrating use of CSS and JavaScript.

See also React Starter.

Half way towards a smiley face -- we used CSS to make the margins and the colors.

We used SVG to make the circles.

Feeling frustrated that we couldn't use math to define the DOM structure and use JSX to write HTML in JS and math from JS

Using React, we used JSX to allow us to include HTML in JS

In order to get the smile, we need to use an arc feature, but there's no such element in SVG. So we need to use D3.

We can use d3-shape to get the arc

MIT Licensed

Similar vizzes