Skip to content

Commit a21e7da

Browse files
committed
chore: memoize array
1 parent f17e15d commit a21e7da

File tree

1 file changed

+14
-8
lines changed
  • packages/react/src/react/views/collections/list/toolbar

1 file changed

+14
-8
lines changed

packages/react/src/react/views/collections/list/toolbar/filter.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use client'
22

3+
import { useMemo } from 'react'
4+
35
import { isThisFieldShapeFilterable, isThisFilterAllowed } from './components/filter/filter-helper'
46
import {
57
CollectionListFilterPanel,
@@ -32,16 +34,20 @@ export function CollectionListFilter(props: CollectionListFilterProps) {
3234

3335
const filterable = props.filterOptions.filter((e) => isThisFieldShapeFilterable(e.fieldShape))
3436

35-
const whatFilterCanIFetch = [] // use this to fetch for optionsName
36-
const whatFilterCanIFormulate = [] // these you will have to create a component to handle the filter value(s) yourself
37+
const { whatFilterCanIFetch, whatFilterCanIFormulate } = useMemo(() => {
38+
const fetchList: typeof filterable = [] // this is those "select" options, will have to fetch for choices
39+
const formulateList: typeof filterable = [] // this is other types, create a filter component to handle each type separately
3740

38-
for (const e of filterable) {
39-
if (e.optionsName) {
40-
whatFilterCanIFetch.push(e)
41-
} else if (isThisFilterAllowed(e.fieldShape.$client.fieldName, props.allowedFilters)) {
42-
whatFilterCanIFormulate.push(e)
41+
for (const e of filterable) {
42+
if (e.optionsName) {
43+
fetchList.push(e)
44+
} else if (isThisFilterAllowed(e.fieldShape.$client.fieldName, props.allowedFilters)) {
45+
formulateList.push(e)
46+
}
4347
}
44-
}
48+
49+
return { whatFilterCanIFetch: fetchList, whatFilterCanIFormulate: formulateList }
50+
}, [filterable, props.allowedFilters])
4551

4652
return (
4753
<CollectionListFilterPanel

0 commit comments

Comments
 (0)