From c61f764c169643b5b0e6faf60d01a976bc7be77a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 25 May 2021 15:58:52 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Memoize=20mapArea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nest_frontend/hooks/useMapAreaState.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nest_frontend/hooks/useMapAreaState.js b/nest_frontend/hooks/useMapAreaState.js index f1b8354..75a94c6 100644 --- a/nest_frontend/hooks/useMapAreaState.js +++ b/nest_frontend/hooks/useMapAreaState.js @@ -1,4 +1,4 @@ -import { useState } from "react" +import { useMemo, useState } from "react" import Coordinates from "../objects/Coordinates" import MapArea from "../objects/MapArea" @@ -9,7 +9,10 @@ import MapArea from "../objects/MapArea" export default function useMapAreaState() { const [zoom, setZoom] = useState(3) const [center, setCenter] = useState(new Coordinates(0, 0)) - const mapArea = MapArea.fromZoomLevel(zoom, center) + const mapArea = useMemo( + () => MapArea.fromZoomLevel(zoom, center), + [zoom, center] + ) return { zoom,