MCPcopy
hub / github.com/Cveinnt/LiveTerm / useHistory

Function useHistory

src/components/history/hook.ts:4–27  ·  view source on GitHub ↗
(defaultValue: Array<History>)

Source from the content-addressed store, hash-verified

2import { History } from './interface';
3
4export const useHistory = (defaultValue: Array<History>) => {
5 const [history, setHistory] = React.useState<Array<History>>(defaultValue);
6 const [command, setCommand] = React.useState<string>('');
7 const [lastCommandIndex, setLastCommandIndex] = React.useState<number>(0);
8
9 return {
10 history,
11 command,
12 lastCommandIndex,
13 setHistory: (value: string) =>
14 setHistory([
15 ...history,
16 {
17 id: history.length,
18 date: new Date(),
19 command,
20 output: value,
21 },
22 ]),
23 setCommand,
24 setLastCommandIndex,
25 clearHistory: () => setHistory([]),
26 };
27};

Callers 1

IndexPageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected