|
1 |
| -import { useMemo, useState } from 'react'; |
| 1 | +import { useMemo, useState, useCallback } from 'react'; |
2 | 2 |
|
3 | 3 | import cx from 'classnames';
|
4 | 4 | import dayjs from 'dayjs';
|
@@ -62,27 +62,30 @@ const Timetable = ({
|
62 | 62 | setShowTrainDetails(!showTrainDetails);
|
63 | 63 | };
|
64 | 64 |
|
65 |
| - const removeAndUnselectTrains = (trainIds: number[]) => { |
| 65 | + const removeAndUnselectTrains = useCallback((trainIds: number[]) => { |
66 | 66 | removeTrains(trainIds);
|
67 | 67 | setSelectedTrainIds([]);
|
68 |
| - }; |
| 68 | + }, []); |
69 | 69 |
|
70 | 70 | const toggleConflictsListExpanded = () => {
|
71 | 71 | setConflictsListExpanded(!conflictsListExpanded);
|
72 | 72 | };
|
73 | 73 |
|
74 |
| - const handleSelectTrain = (id: number) => { |
75 |
| - const currentSelectedTrainIds = [...selectedTrainIds]; |
76 |
| - const index = currentSelectedTrainIds.indexOf(id); |
| 74 | + const handleSelectTrain = useCallback( |
| 75 | + (id: number) => { |
| 76 | + const currentSelectedTrainIds = [...selectedTrainIds]; |
| 77 | + const index = currentSelectedTrainIds.indexOf(id); |
77 | 78 |
|
78 |
| - if (index === -1) { |
79 |
| - currentSelectedTrainIds.push(id); |
80 |
| - } else { |
81 |
| - currentSelectedTrainIds.splice(index, 1); |
82 |
| - } |
| 79 | + if (index === -1) { |
| 80 | + currentSelectedTrainIds.push(id); |
| 81 | + } else { |
| 82 | + currentSelectedTrainIds.splice(index, 1); |
| 83 | + } |
83 | 84 |
|
84 |
| - setSelectedTrainIds(currentSelectedTrainIds); |
85 |
| - }; |
| 85 | + setSelectedTrainIds(currentSelectedTrainIds); |
| 86 | + }, |
| 87 | + [selectedTrainIds] |
| 88 | + ); |
86 | 89 |
|
87 | 90 | const handleConflictClick = (conflict: Conflict) => {
|
88 | 91 | if (conflict.train_ids.length > 0) {
|
|
0 commit comments