timc1 / kbar

fast, portable, and extensible cmd+k interface for your site
https://kbar.vercel.app
MIT License
4.84k stars 185 forks source link

State does not return anything with useKbar() #259

Closed jameswong3388 closed 1 year ago

jameswong3388 commented 1 year ago

I followed the example given in the docs, but it does not seem like returning anything tho. Did I make anymistakes ?

image

function CurrentActions() {
  const { actionAncestors } = useKBar((state) => {
    let actionAncestors = []
    const collectAncestors = (actionId) => {
      const action = state.actions[actionId]
      if (!action.parent) {
        return null
      }
      actionAncestors.unshift(action)
      const parent = state.actions[action.parent]
      collectAncestors(parent)
    }

    return {
      actionAncestors,
    }
  })

  return (
    <div className="flex flex-wrap items-center bg-white px-4 pt-4 text-xs text-gray-700">
      <button className="rounded bg-zinc-100 px-1">home</button>
      {actionAncestors.map((action) => (
        <button key={action}>{action}</button>
      ))}
    </div>
  )
}