|
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"; |
9 | 9 |
|
10 | | -class App extends Component { |
11 | | - constructor (props) { |
12 | | - super(props) |
| 10 | +export default function App() { |
| 11 | + const [selectedChart, setSelectedChart] = useState("line"); |
13 | 12 |
|
14 | | - this.changeChart = this.changeChart.bind(this) |
| 13 | + const handleChartChange = (e) => { |
| 14 | + setSelectedChart(e.target.value); |
| 15 | + }; |
15 | 16 |
|
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> |
20 | 28 |
|
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 | + ); |
48 | 38 | } |
49 | | - |
50 | | -export default App |
0 commit comments