-
Describe the BugI am trying to show a custom import { useListDrawer } from '@payloadcms/ui'
const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({
collectionSlugs: ['routes'],
filterOptions: {
routes: {
location: { equals: fields.location.value },
},
},
}) But as soon as I set the I am porting my app from v2 to v3 beta. Using beta 111 ATM. Looking at the code, the same problem exists in the latest beta and probably in the stable version as well (at least it did when I last tried). So I copy-pasted const MemoizedDrawer = useMemo(() => {
return (props) => (
<ListDrawer
{...props}
closeDrawer={closeDrawer}
collectionSlugs={collectionSlugs}
drawerSlug={drawerSlug}
filterOptions={filterOptionsRef.current}
key={drawerSlug}
selectedCollection={selectedCollection}
uploads={uploads}
/>
)
}, [
drawerSlug,
collectionSlugs,
uploads,
closeDrawer,
selectedCollection,
//filterOptions
]) Not really sure why this is happening. Need to investigate further. Maybe some prop is being mutated? Am I doing something wrong? Link to the code that reproduces this issuehttps://github.com/HriBB/payload-listdrawer-repro Reproduction Steps
import { useListDrawer } from '@payloadcms/ui'
const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({
collectionSlugs: ['routes'],
filterOptions: {
routes: {
location: { equals: fields.location.value },
},
},
}) Which area(s) are affected? (Select all that apply)area: ui Environment InfoBinaries: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @HriBB — you are causing an infinite loop because you are making a new object for your const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({
collectionSlugs: ['routes'],
// This is a newly created object each time the parent component renders!
filterOptions: {
routes: {
location: { equals: fields.location.value },
},
},
}) To fix, you could store the filterOptions in state so it does not change: const [myFilterOptions] = useState({
routes: {
location: { equals: fields.location.value },
},
});
const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({
collectionSlugs: ['routes'],
// Now the object will be equal in subsequent renders
filterOptions: myFilterOptions,
}) |
Beta Was this translation helpful? Give feedback.
Hey @HriBB — you are causing an infinite loop because you are making a new object for your
filterOptions
each time you render here:To fix, you could store the filterOptions in state so it does not change: