File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ describe('LineChart', () => {
2121 expect ( chartRef . current ) . toBeDefined ( )
2222 } )
2323
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+
2432 test ( 'function ref should be called' , ( ) => {
2533 // let chart
2634 const getChart = ( instance ) => {
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export interface BaseChartProps<C extends Options>
5555 | RefCallback < BasePlot < C > | null >
5656 | MutableRefObject < BasePlot < C > | null >
5757 data ?: Record < string , any > | Record < string , any > [ ]
58+ onReady ?: ( plot : BasePlot < C > ) => void
5859}
5960
6061const BaseChart = < C extends Options > (
@@ -66,6 +67,7 @@ const BaseChart = <C extends Options>(
6667 style,
6768 className,
6869 chartRef : chart ,
70+ onReady,
6971 ...restProps
7072 } = props
7173 const chartRef = useRef < BasePlot < C > | null > ( null )
@@ -92,6 +94,9 @@ const BaseChart = <C extends Options>(
9294 chartRef . current . render ( )
9395 }
9496 syncRef ( chartRef , chart )
97+ if ( chartRef . current ) {
98+ onReady ?.( chartRef . current )
99+ }
95100 return ( ) => {
96101 /* istanbul ignore else */
97102 if ( chartRef . current ) {
You can’t perform that action at this time.
0 commit comments