Fix hooks to avoid unnecessary re-renders (#10820)

This commit is contained in:
Tommaso Sciortino
2025-10-09 11:07:25 -07:00
committed by GitHub
parent b60c8858af
commit cd354aebed
3 changed files with 37 additions and 20 deletions
+11 -8
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],
);
}