fix(cli): memoize useHistory() return to avoid unnecessary re-renders (#3547)

This commit is contained in:
qqqys 2026-04-24 22:57:47 +08:00 committed by GitHub
parent 55c63e1a2a
commit 3a2ee4ac1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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],
);
}