Skip to content

Commit

Permalink
fix: Prevent continuously dispatching search/setSearchResults action
Browse files Browse the repository at this point in the history
  • Loading branch information
baumandm committed Jan 19, 2024
1 parent 39d95bd commit 811d084
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/frontend/src/pages/search-page/search-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Box, Stack, VStack } from '@chakra-ui/react';
import { useEffect, useRef } from 'react';
import { useEffect, useMemo, useRef } from 'react';
import { Helmet } from 'react-helmet';
import { useSelector } from 'react-redux';
import { useDispatch } from 'react-redux';
Expand Down Expand Up @@ -49,9 +49,11 @@ export const SearchPage = () => {
useNewSearch
});

const insightResults = data.insights.results.map(({ insight }) => {
return { id: insight.id, name: insight.name, fullName: insight.fullName, itemType: insight.itemType };
});
const insightResults = useMemo(() => {
return data.insights.results.map(({ insight }) => {
return { id: insight.id, name: insight.name, fullName: insight.fullName, itemType: insight.itemType };
});
}, [data.insights.results]);

useEffect(() => {
if (!initialized.current) {
Expand Down

0 comments on commit 811d084

Please sign in to comment.