File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ describe('LineChart', () => {
21
21
expect ( chartRef . current ) . toBeDefined ( )
22
22
} )
23
23
24
+ test ( 'onReady should be called' , ( ) => {
25
+ const onReady = ( plot : BasePlot < LineOptions > ) => {
26
+ expect ( plot ) . toBeDefined ( )
27
+ }
28
+ const div = document . createElement ( 'div' )
29
+ ReactDOM . render ( < LineChart data = { [ ] } onReady = { onReady } /> , div )
30
+ } )
31
+
24
32
test ( 'function ref should be called' , ( ) => {
25
33
// let chart
26
34
const getChart = ( instance ) => {
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export interface BaseChartProps<C extends Options>
55
55
| RefCallback < BasePlot < C > | null >
56
56
| MutableRefObject < BasePlot < C > | null >
57
57
data ?: Record < string , any > | Record < string , any > [ ]
58
+ onReady ?: ( plot : BasePlot < C > ) => void
58
59
}
59
60
60
61
const BaseChart = < C extends Options > (
@@ -66,6 +67,7 @@ const BaseChart = <C extends Options>(
66
67
style,
67
68
className,
68
69
chartRef : chart ,
70
+ onReady,
69
71
...restProps
70
72
} = props
71
73
const chartRef = useRef < BasePlot < C > | null > ( null )
@@ -92,6 +94,9 @@ const BaseChart = <C extends Options>(
92
94
chartRef . current . render ( )
93
95
}
94
96
syncRef ( chartRef , chart )
97
+ if ( chartRef . current ) {
98
+ onReady ?.( chartRef . current )
99
+ }
95
100
return ( ) => {
96
101
/* istanbul ignore else */
97
102
if ( chartRef . current ) {
You can’t perform that action at this time.
0 commit comments