Skip to main content
100%

React + D3 + useData Viz Starter

✓ Published1🌍 Public
MMinwoo Pak
Last edited Jul 15, 2021
Created on Jul 15, 2021

This example demonstrates a minimal React and D3 starter template for building SVG visualizations. It shows how to fetch and parse a CSV dataset from a GitHub gist using a custom `useData` hook that leverages `d3.csv`, and renders the results inside a reusable `VizContainer` component. The container abstracts the SVG and group elements while following a standard margin convention; an optional `showMargins` prop displays placeholder rectangles to visualize the plotting area. The code highlights the integration of React’s state management via `useState` and `useEffect` with D3’s data loading and SVG rendering.

AI-generated description

Boilerplate code for a React + D3 visualization with:

  • CDN links for React, ReactDOM, and D3
  • Basic React boilerplate
  • Variables for dimensions and margins
  • useData hook to fetch a CSV URL.
  • VizContainer component that:
    • Abstracts SVG/group container elements
    • Follows the margin convention
    • Show the margins, which can be easily removed by deleting the showMargins={true} prop
MIT Licensed

Similar vizzes