timc1/kbar

Feature request: Searching remote (async) sources

ohxh opened this issue · 3 comments

ohxh commented

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

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])

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

stale commented

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.