mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
perf: optimize ui components with react hooks memoization
- toggle-group.tsx: Wrap contextValue in useMemo to prevent unnecessary re-renders - animated-tabs.tsx: Hoist constants and memoize handlers with useCallback/useMemo - LocaleContext.tsx: Wrap setLocale in useCallback and contextValue in useMemo - plate-editor.tsx: Memoize SaveShortcutPlugin and contextProviderValue, use useRef for stable references
This commit is contained in:
parent
92d75ad622
commit
af5977691b
4 changed files with 22 additions and 13 deletions
|
|
@ -158,14 +158,16 @@ export function PlateEditor({
|
|||
// When not forced read-only, the user can toggle between editing/viewing.
|
||||
const canToggleMode = !readOnly;
|
||||
|
||||
const contextProviderValue = useMemo(()=> ({
|
||||
onSave,
|
||||
hasUnsavedChanges,
|
||||
isSaving,
|
||||
canToggleMode,
|
||||
}), [onSave, hasUnsavedChanges, isSaving, canToggleMode]);
|
||||
|
||||
return (
|
||||
<EditorSaveContext.Provider
|
||||
value={{
|
||||
onSave,
|
||||
hasUnsavedChanges,
|
||||
isSaving,
|
||||
canToggleMode,
|
||||
}}
|
||||
value={contextProviderValue}
|
||||
>
|
||||
<Plate
|
||||
editor={editor}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue