diff --git a/components/projects/filter.js b/components/projects/filter.js index d005090..db09f75 100644 --- a/components/projects/filter.js +++ b/components/projects/filter.js @@ -1,6 +1,6 @@ -import { useState, useRef, useEffect, useContext } from 'react' -import { Box, Text, Flex, Grid, Input } from 'theme-ui' -import { Row, Column, Badge, Toggle } from '@carbonplan/components' +import { useState, useRef, useEffect, useCallback } from 'react' +import { Box, Flex, Input } from 'theme-ui' +import { Badge, Toggle } from '@carbonplan/components' const Filter = ({ filters, @@ -49,6 +49,10 @@ const Filter = ({ }) } + const handleToggle = useCallback(() => { + hotspotsToggle ? setShowHotspots(!showHotspots) : toggle('updateWithMap') + }, [hotspotsToggle, toggle, setShowHotspots, showHotspots]) + return ( toggle('updateWithMap')} + onClick={handleToggle} sx={{ fontFamily: 'mono', letterSpacing: 'mono', @@ -122,11 +126,7 @@ const Filter = ({ {hotspotsToggle ? 'SHOW THERMAL HOTSPOTS' : 'UPDATE W/ MAP'} - hotspotsToggle - ? setShowHotspots(!showHotspots) - : toggle('updateWithMap') - } + onClick={handleToggle} value={hotspotsToggle ? showHotspots : filters.updateWithMap} sx={{ color: toggleColor,