mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 03:30:40 +00:00
fix(cli): memoize useHistory() return to avoid unnecessary re-renders (#3547)
This commit is contained in:
parent
55c63e1a2a
commit
3a2ee4ac1d
1 changed files with 11 additions and 8 deletions
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useRef, useCallback } from 'react';
|
||||
import { useState, useRef, useCallback, useMemo } from 'react';
|
||||
import type { HistoryItem } from '../types.js';
|
||||
|
||||
// Type for the updater function passed to updateHistoryItem
|
||||
|
|
@ -101,11 +101,14 @@ export function useHistory(): UseHistoryManagerReturn {
|
|||
messageIdCounterRef.current = 0;
|
||||
}, []);
|
||||
|
||||
return {
|
||||
history,
|
||||
addItem,
|
||||
updateItem,
|
||||
clearItems,
|
||||
loadHistory,
|
||||
};
|
||||
return useMemo(
|
||||
() => ({
|
||||
history,
|
||||
addItem,
|
||||
updateItem,
|
||||
clearItems,
|
||||
loadHistory,
|
||||
}),
|
||||
[history, addItem, updateItem, clearItems, loadHistory],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue