Skip to content

useListDrawer filterOptions cause infinite loop #8909

Answered by jmikrut
HriBB asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @HriBB — you are causing an infinite loop because you are making a new object for your filterOptions each time you render here:

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({

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@HriBB
Comment options

Answer selected by HriBB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
2 participants
Converted from issue

This discussion was converted from issue #8907 on October 28, 2024 20:52.