
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Command palette component for React
npm i cmdkit
Simple example
import { CommandPalette } from "cmdkit";
const logTime = {
id: "logTime",
name: "Log current time",
command: () => console.log(new Date()),
view: <p>Running this command will log the current time</p>,
};
const App = () => {
return (
<div>
<CommandPalette commands={[logTime]} />
{/* rest of the app*/}
</div>
);
};
Advanced example
// index.ts - outside of where `CommandPalette` is used
import { CommandEventProvider } from "cmdkit";
ReactDOM.render(
<CommandEventProvider>
<App />
</CommandEventProvider>,
document.getElementById("root")
);
// App.tsx
import { CommandPalette, useAppearEvent } from "cmdkit";
const useCounterLog = () => {
const id = "counterLog";
const [count, setCount] = useState(0);
useAppearEvent(id, () => setCount((prev) => prev + 1));
return {
id,
name: `Log the current time`,
command: () => console.log(new Date()),
view: <p>This command has appeared in the search results {count} times</p>,
};
};
const App = () => {
const counterLog = useCounterLog();
return (
<div>
<CommandPalette commands={[counterLog]} />
{/* rest of the app*/}
</div>
);
};
Command<CommandPalette /> accepts a list of Commands, which is an object with the following properties:
id A string that uniquely identifies the commandname The displayed name in the command palettecommand (Optional) The function to run when the command is selectedview (Optional) A React element to show in the pane next to the search resultsimport { Command } from "cmdkit";
const logTime: Command = {
id: "logTime",
name: "Log the current time",
command: () => console.log(new Date()),
view: (
<div>
<p>This command logs the current time</p>
</div>
),
};
CommandPaletteRenders a command palette in your application
⌘ + K (Mac) or Alt + K (Windows).EnterEsc to closeAccepts a list of Commands through the commands prop.
import { CommandPalette } from "cmdkit";
const App = () => (
<div>
<CommandPalette
commands={[
{
id: "simpleCommand",
name: "A simple command",
command: () => console.log("That was simple!"),
},
]}
/>
<h1>My app</h1>
</div>
);
CommandEventProviderManages the state of event hooks which commands can use to provide advanced functionality.
Must be used outside the component which renders the <CommandPalette /> component.
import { CommandPalette, CommandEventProvider } from "cmdkit"
const App = () => <div>
<CommandPalette commands={...} />
<h1>My app</h1>
</div>
const Root = () => <CommandEventProvider>
<App />
</CommandEventProvider>
cmdkit provides a couple of hooks for tapping into a command's life cycle.
Note: Usage of these hooks must happen within a CommandEventProvider />
useAppearEventAllows you to run code when the command appears in the search results. Will re-run each time the command appears.
import { useAppearEvent } from "cmdkit";
useAppearEvent("myCommand", () => console.log("just appeared!"));
useFocusEventAllows you to run code when the command receives focus in the search results.
import { useFocusEvent } from "cmdkit";
useFocusEvent("myCommand", () => console.log("received focus!"));
useBlurEventAllows you to run code when the command loses focus in the search results.
import { useFocusEvent } from "cmdkit";
useFocusEvent("myCommand", () => console.log("lost focus!"));
useExecuteEventAllows you to run additional code when a command is executed.
Most of the time you would probably include this code directly in the command's command function, but it might be useful if the command in question isn't in scope of whatever is depending on it.
import { useExecuteEvent } from "cmdkit";
useExecuteEvent("myCommand", () => console.log("command was executed"));
useDoneEventAllows you to run additional code when a command has finished executing.
import { useDoneEvent } from "cmdkit";
useDoneEvent("myCommand", () => console.log("command is done excecuting!"));
FAQs
Command palette component for React
We found that cmdkit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.