Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created June 23, 2023 13:50
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 sethdavis512/021e04c0950a3b05f6217dbc41140ab1 to your computer and use it in GitHub Desktop.
Save sethdavis512/021e04c0950a3b05f6217dbc41140ab1 to your computer and use it in GitHub Desktop.
React hook for D3 usage
const useD3 = (renderChartFn: (el: any) => void, dependencies: any[]) => {
const ref = useRef<HTMLElement>();
useEffect(() => {
if (!!ref.current) {
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