MCPcopy
hub / github.com/ChatGPTNextWeb/NextChat / useCommand

Function useCommand

app/command.ts:14–33  ·  view source on GitHub ↗
(commands: Commands = {})

Source from the content-addressed store, hash-verified

12}
13
14export function useCommand(commands: Commands = {}) {
15 const [searchParams, setSearchParams] = useSearchParams();
16
17 useEffect(() => {
18 let shouldUpdate = false;
19 searchParams.forEach((param, name) => {
20 const commandName = name as keyof Commands;
21 if (typeof commands[commandName] === "function") {
22 commands[commandName]!(param);
23 searchParams.delete(name);
24 shouldUpdate = true;
25 }
26 });
27
28 if (shouldUpdate) {
29 setSearchParams(searchParams);
30 }
31 // eslint-disable-next-line react-hooks/exhaustive-deps
32 }, [searchParams, commands]);
33}
34
35interface ChatCommands {
36 new?: Command;

Callers 2

NewChatFunction · 0.90
_ChatFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected