@@ -46,16 +46,17 @@ export default function Charts({
46
46
height = "auto" ,
47
47
series,
48
48
options,
49
+ chartRef,
49
50
...restProps
50
51
} ) {
51
- const chartRef = useRef ( null ) ;
52
- let chart = useRef ( null ) ;
52
+ const chartElementRef = useRef ( null ) ;
53
+ let chart = chartRef || useRef ( null ) ;
53
54
const prevOptions = useRef ( )
54
55
55
56
useEffect ( ( ) => {
56
57
prevOptions . current = options ;
57
58
58
- const current = chartRef . current ;
59
+ const current = chartElementRef . current ;
59
60
chart . current = new ApexCharts ( current , getConfig ( ) ) ;
60
61
chart . current . render ( ) ;
61
62
@@ -124,13 +125,14 @@ export default function Charts({
124
125
125
126
const rest = omit ( restProps , Object . keys ( Charts . propTypes ) ) ;
126
127
127
- return < div ref = { chartRef } { ...rest } /> ;
128
+ return < div ref = { chartElementRef } { ...rest } /> ;
128
129
}
129
130
130
131
Charts . propTypes = {
131
132
type : PropTypes . string . isRequired ,
132
133
series : PropTypes . array . isRequired ,
133
134
options : PropTypes . object . isRequired ,
134
135
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 } )
136
138
} ;
0 commit comments