Skip to content

Commit d567a29

Browse files
committed
feat: use chartRef instead of ref
1 parent 3b9bc5e commit d567a29

File tree

6 files changed

+881
-746
lines changed

6 files changed

+881
-746
lines changed

__tests__/plots/line.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ describe('LineChart', () => {
1212

1313
test('object ref should be assigned', () => {
1414
const ref = createRef<any>()
15+
const chartRef = createRef()
1516
const div = document.createElement('div')
16-
ReactDOM.render(<LineChart data={[]} ref={ref} />, div)
17-
17+
ReactDOM.render(<LineChart data={[]} ref={ref} chartRef={chartRef} />, div)
1818
expect(ref.current).toBeDefined()
19+
expect(chartRef.current).toBeDefined()
1920
})
2021

2122
test('function ref should be called', () => {

docs/api/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nav:
66

77
## Configurations
88

9-
All configurations defined in `G2Plot` can be used as `props`, and use `ref` can access chart instance
9+
All configurations defined in `G2Plot` can be used as `props`, and use `chartRef` can access chart instance
1010

1111
For example
1212

@@ -16,7 +16,10 @@ import { LineChart } from '@opd/g2plot-react'
1616

1717
export default () => {
1818
const ref = useRef()
19-
return <LineChart xField="x" height={400} ref={ref} forceFit />
19+
const chartRef = useRef()
20+
return (
21+
<LineChart xField="x" height={400} ref={ref} chartRef={chartRef} forceFit />
22+
)
2023
}
2124
```
2225

docs/guide/get-started.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ export default () => {
110110
const getChart = useCallback((chart) => {
111111
console.log(chart)
112112
}, [])
113-
return <LineChart {...config} ref={getChart} />
113+
const getContainer = useCallback((container) => {
114+
console.log(container)
115+
}, [])
116+
return <LineChart {...config} ref={getContainer} chartRef={getChart} />
114117
}
115118
```

0 commit comments

Comments
 (0)