Skip to content

Instantly share code, notes, and snippets.

@MassivDash
Last active November 6, 2021 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MassivDash/86a152e762975f2601ff3895830be89e to your computer and use it in GitHub Desktop.
Save MassivDash/86a152e762975f2601ff3895830be89e to your computer and use it in GitHub Desktop.
useD3 react hook
import React from 'react';
import * as d3 from 'd3';
export const useD3 = (renderChartFn, dependencies) => {
const ref = React.useRef();
React.useEffect(() => {
renderChartFn(d3.select(ref.current));
return () => {};
}, dependencies);
return ref;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment