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

Feature request: Searching remote (async) sources #280

Closed ohxh closed 1 year ago

ohxh commented 1 year ago

This project looks very high quality and I'm interested in using it in an app I'm building. However, I want to do some search on the backend too in some actions (think Search Docs > [query goes here]. Ideally, I could provide my own function search: (x: query) => Promise<Action[]> or whatever. Is this a direction you want to take this project / a contribution you'd be interested in?

Possible related to #255 too

timc1 commented 1 year ago

Hey @ohxh! 100% would benefit from first class support for async loading of actions. As a little hack for now you can work with useRegisterActions to in a way to replicate the search -> action experience:

const [search, setSearch] = React.useState("");

const actions = React.useMemo(() => {
  const results = await getResults(search);
  return results.map(r => createAction(...));
}, [search]);

useRegisterActions(actions, [actions])
vsnthdev commented 1 year ago

I used useRegisterActions() and useState() to take the search query, fetch results from a RESTful API and render results on the fly.

stale[bot] commented 1 year ago

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.