@@ -46,16 +46,17 @@ export default function Charts({
4646 height = "auto" ,
4747 series,
4848 options,
49+ chartRef,
4950 ...restProps
5051} ) {
51- const chartRef = useRef ( null ) ;
52- let chart = useRef ( null ) ;
52+ const chartElementRef = useRef ( null ) ;
53+ let chart = chartRef || useRef ( null ) ;
5354 const prevOptions = useRef ( )
5455
5556 useEffect ( ( ) => {
5657 prevOptions . current = options ;
5758
58- const current = chartRef . current ;
59+ const current = chartElementRef . current ;
5960 chart . current = new ApexCharts ( current , getConfig ( ) ) ;
6061 chart . current . render ( ) ;
6162
@@ -124,13 +125,14 @@ export default function Charts({
124125
125126 const rest = omit ( restProps , Object . keys ( Charts . propTypes ) ) ;
126127
127- return < div ref = { chartRef } { ...rest } /> ;
128+ return < div ref = { chartElementRef } { ...rest } /> ;
128129}
129130
130131Charts . propTypes = {
131132 type : PropTypes . string . isRequired ,
132133 series : PropTypes . array . isRequired ,
133134 options : PropTypes . object . isRequired ,
134135 width : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
135- height : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] )
136+ height : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
137+ chartRef : PropTypes . shape ( { current : PropTypes . any } )
136138} ;
0 commit comments