timc1 / kbar

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

State does not return anything with useKbar() #259

Closed jameswong3388 closed 2 years ago

jameswong3388 commented 2 years 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>
  )
}