Kvaser CanKing GUI Extensions SDK v7.4.0
Kvaser CanKing GUI Extensions SDK / hooks / useSessionDataSlice
Function: useSessionDataSlice()
useSessionDataSlice<
T>(id,slice,defaultValue,loadedCallback?): [T,Dispatch<SetStateAction<T>>,boolean]
A hook for persistent (session) data tied to a specific view slice. The state is automatically saved to and restored from the main process.
Type Parameters
T
T
The type of the session data. Must be JSON serializable.
Parameters
id
number
The unique id of the view. This is passed to the view component as the id prop.
slice
string
The slice name for the session data.
defaultValue
The default value or a function that returns the default value.
T | () => T
loadedCallback?
(value) => void
Optional callback invoked once after data is loaded.
Returns
[T, Dispatch<SetStateAction<T>>, boolean]
[state, setState, loaded] — the current data, setter, and loaded flag.
Remarks
Use this hook to split your workspace view’s session data into multiple named slices.
This can improve performance and reduce memory usage and it also allows
different parts of the component tree to independently load and save their session data.
Make sure to use the workspace view component’s id prop and to use unique slice names
for each slice within the component tree.