From a49cac6692413b68b698dfc17796969d17ad907e Mon Sep 17 00:00:00 2001 From: DinizSa Date: Wed, 20 Nov 2024 20:03:40 +0200 Subject: [PATCH] fix: hook infinite loop call --- .../whitelist/hooks/useGetFilteredBuilders.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/app/collective-rewards/whitelist/hooks/useGetFilteredBuilders.ts b/src/app/collective-rewards/whitelist/hooks/useGetFilteredBuilders.ts index 15acfa1c..73dbd7e0 100644 --- a/src/app/collective-rewards/whitelist/hooks/useGetFilteredBuilders.ts +++ b/src/app/collective-rewards/whitelist/hooks/useGetFilteredBuilders.ts @@ -1,7 +1,7 @@ -import { useEffect, useState } from 'react' -import { BuilderStatusFilter } from '@/app/collective-rewards/whitelist' -import { BuilderProposal, useBuilderContext } from '@/app/collective-rewards/user' import { BuilderStateDetails } from '@/app/collective-rewards/types' +import { useBuilderContext } from '@/app/collective-rewards/user' +import { BuilderStatusFilter } from '@/app/collective-rewards/whitelist' +import { useMemo } from 'react' type FetchWhitelistedBuildersFilter = { builderName: string @@ -16,10 +16,9 @@ export const useGetFilteredBuilders = ({ status: filterStatus, stateFlags, }: FetchWhitelistedBuildersFilter) => { - const [data, setData] = useState([]) const { data: builders, isLoading, error } = useBuilderContext() - useEffect(() => { + const data = useMemo(() => { let filteredBuilders = builders if (filterBuilderName) { @@ -42,8 +41,7 @@ export const useGetFilteredBuilders = ({ if (filterStatus !== 'all') { filteredBuilders = filteredBuilders.filter(builder => builder.status === filterStatus) } - - setData(filteredBuilders) + return filteredBuilders }, [builders, filterBuilderName, filterStatus, stateFlags]) return {