Skip to content

hooks/useSaveLoad#

useSaveLoad()#

function useSaveLoad<TProtocol>(config): SaveLoadActions;

Hook for save/load functionality with entity browser integration

Type Parameters#

Type Parameter Default type
TProtocol any

Parameters#

Parameter Type
config SaveLoadConfig<TProtocol>

Returns#

SaveLoadActions

Example#

const { pluginId, sendMessage } = usePluginContext()
const state = useSharedPluginState<MyState>()

const saveLoad = useSaveLoad({
  pluginId,
  sendMessage,
  currentEntityName: state?.name
})

// Use with EntityBrowser
<EntityBrowser.Dialog
  entityType={saveLoad.entityType}
  onSelect={saveLoad.load}
/>

SaveLoadActions#

Properties#

entityType#

entityType: string;

Entity type ID for use with EntityBrowser

list#

list: () => Promise<string[]>;

Get list of entities

Returns#

Promise<string[]>

load#

load: (name) => Promise<void>;

Load an entity

Parameters#
Parameter Type
name string
Returns#

Promise<void>

save#

save: (name) => Promise<void>;

Save current entity

Parameters#
Parameter Type
name string
Returns#

Promise<void>


SaveLoadConfig#

useSaveLoad Hook

Provides developer-friendly save/load functionality for plugins. Automatically handles: - Entity browser registration - Save/Load dialogs - Backend communication

Extended by#

Type Parameters#

Type Parameter Default type
TProtocol any

Properties#

currentEntityName?#

optional currentEntityName?: string;

Current entity name (for highlighting in entity browser)

entityTypeSuffix?#

optional entityTypeSuffix?: string;

Custom entity type suffix (default: 'entities')

methods?#

optional methods?: {
  list?: keyof TProtocol;
  load?: keyof TProtocol;
  preview?: keyof TProtocol;
  save?: keyof TProtocol;
};

Backend method names - type-safe against protocol interface

list?#
optional list?: keyof TProtocol;
load?#
optional load?: keyof TProtocol;
preview?#
optional preview?: keyof TProtocol;
save?#
optional save?: keyof TProtocol;

previewComponent?#

optional previewComponent?: ComponentType<{
  entityName: string;
  previewData: any;
}>;

Optional custom preview component