Skip to content

Commit 22e3665

Browse files
committed
useCallback & useMemo
1 parent 65f119b commit 22e3665

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

app/charts/RouteChart.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CommsContext } from '../context/CommsContext';
66
// import { log } from 'console';
77
import Graph from 'react-graph-vis';
88

9-
const RouteLocations = React.memo((props) => {
9+
const RouteLocations = React.memo(() => {
1010
const communicationsData = useContext(CommsContext).commsData;
1111
console.log('commdata=======>', communicationsData);
1212
console.log('try again');

app/context/ApplicationContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { ipcRenderer } = window.require('electron');
1212
*/
1313
export const ApplicationContext = React.createContext<any>(null);
1414

15-
const ApplicationContextProvider: React.FC = ({ children }) => {
15+
const ApplicationContextProvider: React.FC = React.memo(({ children }) => {
1616
const [servicesData, setServicesData] = useState([]);
1717
const [app, setApp] = useState<string>('');
1818

@@ -79,6 +79,6 @@ const ApplicationContextProvider: React.FC = ({ children }) => {
7979
{children}
8080
</ApplicationContext.Provider>
8181
);
82-
};
82+
});
8383

8484
export default ApplicationContextProvider;

app/context/CommsContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const CommsContext = React.createContext<any>(null);
1111
* @method setCommsData
1212
* @method fetchCommsData
1313
*/
14-
const CommsContextProvider: React.SFC = ({ children }) => {
14+
const CommsContextProvider: React.SFC = React.memo(({ children }) => {
1515
const [commsData, setCommsData] = useState([]);
1616
const [currentApp, setCurrentApp] = useState('');
1717

@@ -58,6 +58,6 @@ const CommsContextProvider: React.SFC = ({ children }) => {
5858
{children}
5959
</CommsContext.Provider>
6060
);
61-
};
61+
});
6262

6363
export default CommsContextProvider;

app/context/DashboardContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const DashboardContext = createContext<any>(null);
2222
* @method addApp
2323
* @method deleteApp
2424
*/
25-
const DashboardContextProvider = ({ children }: Props) => {
25+
const DashboardContextProvider = React.memo(({ children }: Props) => {
2626
const [applications, setApplications] = useState<string[]>([]);
2727

2828
/**
@@ -63,6 +63,6 @@ const DashboardContextProvider = ({ children }: Props) => {
6363
{children}
6464
</DashboardContext.Provider>
6565
);
66-
};
66+
});
6767

6868
export default DashboardContextProvider;

app/context/DockerContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const DockerContext = React.createContext<any>(null);
1313
* @method setDockerData
1414
* @method fetchDockerData
1515
*/
16-
const DockerContextProvider: React.SFC = ({ children }) => {
16+
const DockerContextProvider: React.FC = React.memo(({ children }) => {
1717
const [dockerData, setDockerData] = useState({});
1818

1919
function tryParseJSON(jsonString: any) {
@@ -55,6 +55,6 @@ const DockerContextProvider: React.SFC = ({ children }) => {
5555
{children}
5656
</DockerContext.Provider>
5757
);
58-
};
58+
});
5959

6060
export default DockerContextProvider;

app/context/HealthContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const HealthContext = React.createContext<any>(null);
1010
* @method parseHealthData
1111
* @method setHealthData
1212
*/
13-
const HealthContextProvider: React.SFC = ({ children }) => {
13+
const HealthContextProvider: React.FC = React.memo(({ children }) => {
1414
const [healthData, setHealthData] = useState({});
1515

1616
function tryParseJSON(jsonString:any) {
@@ -65,6 +65,6 @@ const HealthContextProvider: React.SFC = ({ children }) => {
6565
{children}
6666
</HealthContext.Provider>
6767
);
68-
};
68+
});
6969

7070
export default HealthContextProvider;

app/modals/AddModal.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useContext } from 'react';
1+
import React, { useState, useContext, useCallback } from 'react';
22
import { DashboardContext } from '../context/DashboardContext';
33
import '../stylesheets/AddModal.scss';
44

@@ -31,20 +31,20 @@ const AddModal: React.FC<AddModalProps> = React.memo(({ setOpen }) => {
3131
});
3232

3333
// Submit form data and save to database
34-
const handleSubmit = (event: FormElement) => {
34+
const handleSubmit = useCallback((event: FormElement) => {
3535
event.preventDefault();
3636
addApp(fields);
3737
setOpen(false); // Close modal on submit
38-
};
38+
}, []);
3939

4040
// Handle form changes
41-
const handleChange = (event: InputElement) => {
41+
const handleChange = useCallback((event: InputElement) => {
4242
const { name, value } = event.target;
4343
setFields({
4444
...fields,
4545
[name]: value,
4646
});
47-
};
47+
}, []);
4848

4949
const { database, URI, name, description } = fields;
5050

0 commit comments

Comments
 (0)