Skip to content

Commit e06dd26

Browse files
Update following feedback
1 parent 8b2a79d commit e06dd26

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

React/src/App.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { useState } from 'react';
22
import './App.css';
33

44
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
@@ -31,11 +31,7 @@ const chartData = [
3131
];
3232

3333
function calculateAverageSpend(): number {
34-
let sum = 0;
35-
36-
chartData.forEach((data) => {
37-
sum += data.actualSpend;
38-
});
34+
const sum = chartData.reduce((accumulator, { actualSpend }) => accumulator + actualSpend, 0);
3935

4036
return sum / chartData.length;
4137
}
@@ -61,8 +57,12 @@ const chartGradient = registerGradient('linear', {
6157
});
6258

6359
function App(): JSX.Element {
60+
// This example implements useState() for averageSpend to avoid setting the property on each render cycle.
61+
// The useState() setter function is not declared as it is unused in this app.
62+
const [averageSpend] = useState(calculateAverageSpend());
63+
6464
return (
65-
<React.Fragment>
65+
<>
6666
<Chart
6767
dataSource={chartData}
6868
title='Target vs Actual Spending 2024'
@@ -83,7 +83,7 @@ function App(): JSX.Element {
8383
/>
8484
<ValueAxis>
8585
<ConstantLine
86-
value={calculateAverageSpend()}
86+
value={averageSpend}
8787
color='#0000c7'
8888
>
8989
<Label text='Yearly Spend Average' />
@@ -101,7 +101,7 @@ function App(): JSX.Element {
101101
</BackgroundColor>
102102
</CommonPaneSettings>
103103
</Chart>
104-
</React.Fragment>
104+
</>
105105
);
106106
}
107107

0 commit comments

Comments
 (0)