Skip to content

Commit f2f8987

Browse files
samfrostjerairrest
authored andcommitted
Update ref syntax to the new React.createRef() API (#403)
1 parent 3855af1 commit f2f8987

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,19 @@ In order for Chart.js to obey the custom size you need to set `maintainAspectRat
8585
Chart.js instance can be accessed by placing a ref to the element as:
8686

8787
```js
88-
chartReference = {};
88+
class MyComponent extends React.Component {
89+
constructor(props) {
90+
super(props);
91+
this.chartReference = React.createRef();
92+
}
8993

90-
componentDidMount() {
91-
console.log(this.chartReference); // returns a Chart.js instance reference
92-
}
94+
componentDidMount() {
95+
console.log(this.chartReference); // returns a Chart.js instance reference
96+
}
9397

94-
render() {
95-
return (<Doughnut ref={(reference) => this.chartReference = reference } data={data} />)
98+
render() {
99+
return (<Doughnut ref={this.chartReference} data={data} options={options} />)
100+
}
96101
}
97102
```
98103

0 commit comments

Comments
 (0)