Skip to main content
Public

Share visualization

Loading preview…

Basic React Hook Test (Circles - Fixed Data)

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Basic React Hook Test (Circles - Fixed Data)

1
TTom-S82
Last edited Feb 17, 2020
Created on Feb 16, 2020
Forked from Smiley Face Part 1

This example demonstrates how React hooks can manage D3-driven SVG circle updates with fixed data. The app initializes an array of seven values, rendering each as a grey circle with a blue stroke, positioned via attributes calculated from the data. Two buttons trigger state changes: “Update Data” adds five to every value, while “Filter Data” removes values above 35, causing D3’s join method to add, remove, or update circles accordingly. The code uses the `useRef`, `useState`, and `useEffect` hooks, alongside `d3.select` and `.join()`, with React 16.12 and D3 v5.

AI-generated description

Following along with Muri's basic tutorial on how to set up React hooks with D3.

Comments

Sign in to join the discussion.

MIT Licensed