Created
June 23, 2023 13:50
-
-
Save sethdavis512/021e04c0950a3b05f6217dbc41140ab1 to your computer and use it in GitHub Desktop.
React hook for D3 usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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