diff --git a/packages/ui/src/elements/WhereBuilder/index.tsx b/packages/ui/src/elements/WhereBuilder/index.tsx index 4c2644175..d9b4b21bd 100644 --- a/packages/ui/src/elements/WhereBuilder/index.tsx +++ b/packages/ui/src/elements/WhereBuilder/index.tsx @@ -1,5 +1,5 @@ 'use client' -import type { Operator, Where } from 'payload' +import type { Operator } from 'payload' import { getTranslation } from '@payloadcms/translations' import React, { useMemo } from 'react' @@ -32,7 +32,7 @@ export const WhereBuilder: React.FC = (props) => { const { handleWhereChange, query } = useListQuery() - const [conditions, setConditions] = React.useState(() => { + const conditions = useMemo(() => { const whereFromSearch = query.where if (whereFromSearch) { @@ -51,7 +51,7 @@ export const WhereBuilder: React.FC = (props) => { } return [] - }) + }, [query.where]) const addCondition: AddCondition = React.useCallback( async ({ andIndex, field, orIndex, relation }) => { @@ -77,8 +77,7 @@ export const WhereBuilder: React.FC = (props) => { }) } - setConditions(newConditions) - await handleWhereChange({ or: conditions }) + await handleWhereChange({ or: newConditions }) }, [conditions, handleWhereChange], ) @@ -100,8 +99,7 @@ export const WhereBuilder: React.FC = (props) => { const newConditions = [...conditions] newConditions[orIndex].and[andIndex] = newRowCondition - setConditions(newConditions) - await handleWhereChange({ or: conditions }) + await handleWhereChange({ or: newConditions }) } }, [conditions, handleWhereChange], @@ -116,8 +114,7 @@ export const WhereBuilder: React.FC = (props) => { newConditions.splice(orIndex, 1) } - setConditions(newConditions) - await handleWhereChange({ or: conditions }) + await handleWhereChange({ or: newConditions }) }, [conditions, handleWhereChange], ) diff --git a/packages/ui/src/providers/ListQuery/index.tsx b/packages/ui/src/providers/ListQuery/index.tsx index de7938f4a..c0435a012 100644 --- a/packages/ui/src/providers/ListQuery/index.tsx +++ b/packages/ui/src/providers/ListQuery/index.tsx @@ -45,13 +45,6 @@ export const ListQueryProvider: React.FC = ({ } }) - // If the search params change externally, update the current query - useEffect(() => { - if (modifySearchParams) { - setCurrentQuery(searchParams) - } - }, [searchParams, modifySearchParams]) - const refineListData = useCallback( // eslint-disable-next-line @typescript-eslint/require-await async (query: ListQuery) => {