import * as React from "react"; import Code from "../Code"; export default function GettingStarted() { return (

Getting started

Get a simple command bar up and running quickly. In this example, we will use the APIs provided by kbar out of the box:

There is a single provider which you will wrap your app around; you do not have to wrap your entire app; however, there are no performance implications by doing so.

// ... ); } `} />

Let's add a few default actions. Actions are the core of kbar – an action define what to execute when a user selects it.

(window.location.pathname = "blog"), }, { id: "contact", name: "Contact", shortcut: ["c"], keywords: "email", perform: () => (window.location.pathname = "contact"), }, ] return ( // ... ); `} />

Next, we will pull in the provided UI components from kbar:

// Renders the content outside the root node // Centers the content // Handles the show/hide and height animations // Search input ; ); } `} />

At this point hitting cmd+k will animate in a search input and nothing more.

kbar provides a few utilities to render a performant list of search results.

  • useMatches at its core returns a flattened list of results based on the current search query. This is a list of{" "} string and Action types.
  • KBarResults takes the flattened list of results and renders them within a virtualized window.

Combine the two utilities to create a powerful search interface:

// // ... function RenderResults() { const { results } = useMatches(); return ( typeof item === "string" ? (
{item}
) : (
{item.name}
) } /> ); }`} />

Hit cmd+k (or ctrl+k) and you should see a primitive command menu. kbar allows you to have full control over all aspects of your command menu.

); }