Skip to content

Commit

Permalink
reafactor: change useEffect by useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeart81 committed Jun 29, 2024
1 parent 9855a34 commit fd3a8a1
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/reports/CombinedReportPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import {
Table, TableBody, TableCell, TableHead, TableRow,
Expand Down Expand Up @@ -26,13 +26,8 @@ const CombinedReportPage = () => {

const [items, setItems] = useState([]);
const [loading, setLoading] = useState(false);
const [itemsCoordinates, setItemsCoordinates] = useState([]);

const itemsRoutes = items.flatMap((item) => item.route);

useEffect(() => {
setItemsCoordinates(itemsRoutes);
}, [itemsRoutes.length]);
const itemsCoordinates = useMemo(() => items.flatMap((item) => item.route), [items]);

const createMarkers = () => items.flatMap((item) => item.events
.map((event) => item.positions.find((p) => event.positionId === p.id))
Expand Down

0 comments on commit fd3a8a1

Please sign in to comment.