pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.68k stars 279 forks source link

Fix forceMount too many rerenders #143

Closed joaom00 closed 8 months ago

joaom00 commented 1 year ago

When using the following code to add a "Create action", React throws Maximum update depth exceeded error because filtered.count will loop update between 0 and 1

const search = useCommandState((state) => state.search)
const isEmpty = useCommandState((state) => state.filtered.count === 0)

return isEmpty ? <Command.Item forceMount>Create {search}</Command.Item> : null

To fix this the Item is not registered to be filtered when forceMount is true

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cmdk-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2023 1:03am