Skip to content

Commit 30bc9f8

Browse files
committed
Convert all the example components, class to function components.
1 parent 688e62a commit 30bc9f8

File tree

8 files changed

+342
-451
lines changed

8 files changed

+342
-451
lines changed

example/src/App.js

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,38 @@
1-
import React, { Component } from 'react'
2-
import Area from './chart-types/Area'
3-
import Bar from './chart-types/Bar'
4-
import Column from './chart-types/Column'
5-
import Line from './chart-types/Line'
6-
import Donut from './chart-types/Donut'
7-
import RadialBar from './chart-types/RadialBar'
8-
import ChartUpdate from './ChartUpdate'
1+
import React, { useState } from "react";
2+
import Area from "./chart-types/Area";
3+
import Bar from "./chart-types/Bar";
4+
import Column from "./chart-types/Column";
5+
import Line from "./chart-types/Line";
6+
import Donut from "./chart-types/Donut";
7+
import RadialBar from "./chart-types/RadialBar";
8+
import ChartUpdate from "./ChartUpdate";
99

10-
class App extends Component {
11-
constructor (props) {
12-
super(props)
10+
export default function App() {
11+
const [selectedChart, setSelectedChart] = useState("line");
1312

14-
this.changeChart = this.changeChart.bind(this)
13+
const handleChartChange = (e) => {
14+
setSelectedChart(e.target.value);
15+
};
1516

16-
this.state = {
17-
selectedChart: 'line'
18-
}
19-
}
17+
return (
18+
<div className="app">
19+
<select id="lang" value={selectedChart} onChange={handleChartChange}>
20+
<option value="line">Line</option>
21+
<option value="area">Area</option>
22+
<option value="bar">Bar</option>
23+
<option value="column">Column</option>
24+
<option value="radialbar">RadialBar</option>
25+
<option value="donut">Donut</option>
26+
<option value="updateExample">Chart Update Example</option>
27+
</select>
2028

21-
changeChart (e) {
22-
this.setState({selectedChart: e.target.value})
23-
}
24-
25-
render () {
26-
return (
27-
<div className="app">
28-
<select id="lang" value={this.state.selectedChart} onChange={this.changeChart}>
29-
<option value="line" >Line</option>
30-
<option value="area" >Area</option>
31-
<option value="bar" >Bar</option>
32-
<option value="column" >Column</option>
33-
<option value="radialbar" >RadialBar</option>
34-
<option value="donut" >Donut</option>
35-
<option value="updateExample" >Chart Update Example</option>
36-
</select>
37-
38-
{ this.state.selectedChart === 'area' ? (<Area></Area>) : null}
39-
{ this.state.selectedChart === 'bar' ? (<Bar></Bar>) : null}
40-
{ this.state.selectedChart === 'line' ? (<Line></Line>) : null}
41-
{ this.state.selectedChart === 'column' ? (<Column></Column>) : null}
42-
{ this.state.selectedChart === 'radialbar' ? (<RadialBar></RadialBar>) : null}
43-
{ this.state.selectedChart === 'donut' ? (<Donut></Donut>) : null}
44-
{ this.state.selectedChart === 'updateExample' ? (<ChartUpdate></ChartUpdate>) : null}
45-
</div>
46-
)
47-
}
29+
{selectedChart === "area" ? <Area></Area> : null}
30+
{selectedChart === "bar" ? <Bar></Bar> : null}
31+
{selectedChart === "line" ? <Line></Line> : null}
32+
{selectedChart === "column" ? <Column></Column> : null}
33+
{selectedChart === "radialbar" ? <RadialBar></RadialBar> : null}
34+
{selectedChart === "donut" ? <Donut></Donut> : null}
35+
{selectedChart === "updateExample" ? <ChartUpdate></ChartUpdate> : null}
36+
</div>
37+
);
4838
}
49-
50-
export default App

0 commit comments

Comments
 (0)